Browse Source

Make DefaultTypeDefinition.FullName cache thread-safe.

newNRvisualizers
Daniel Grunwald 15 years ago
parent
commit
475f8381ef
  1. 11
      ICSharpCode.NRefactory.CSharp/Ast/CSharpModifierToken.cs
  2. 25
      ICSharpCode.NRefactory/TypeSystem/Implementation/DefaultTypeDefinition.cs

11
ICSharpCode.NRefactory.CSharp/Ast/CSharpModifierToken.cs

@ -57,8 +57,8 @@ namespace ICSharpCode.NRefactory.CSharp @@ -57,8 +57,8 @@ namespace ICSharpCode.NRefactory.CSharp
Modifiers.Abstract, Modifiers.Virtual, Modifiers.Sealed, Modifiers.Static, Modifiers.Override,
Modifiers.Readonly, Modifiers.Volatile,
Modifiers.Extern, Modifiers.Partial, Modifiers.Const,
Modifiers.Any,
Modifiers.Async
Modifiers.Async,
Modifiers.Any
};
public static IEnumerable<Modifiers> AllModifiers {
@ -105,12 +105,11 @@ namespace ICSharpCode.NRefactory.CSharp @@ -105,12 +105,11 @@ namespace ICSharpCode.NRefactory.CSharp
return "volatile";
case Modifiers.Unsafe:
return "unsafe";
case Modifiers.Any:
// even though it's used for patterns only, it needs to be in this list to be usable in the AST
return "any";
case Modifiers.Async:
// even though it's used for patterns only, it needs to be in this list to be usable in the AST
return "async";
case Modifiers.Any:
// even though it's used for pattern matching only, 'any' needs to be in this list to be usable in the AST
return "any";
default:
throw new NotSupportedException("Invalid value for Modifiers");
}

25
ICSharpCode.NRefactory/TypeSystem/Implementation/DefaultTypeDefinition.cs

@ -216,16 +216,25 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -216,16 +216,25 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
}
}
string cachedFullName = null;
[NonSerialized]
volatile string cachedFullName;
public string FullName {
get {
if (cachedFullName != null)
return cachedFullName;
if (declaringTypeDefinition != null)
return cachedFullName = declaringTypeDefinition.FullName + "." + this.name;
if (string.IsNullOrEmpty(ns))
return cachedFullName = this.name;
return cachedFullName = this.ns + "." + this.name;
string fullName = this.cachedFullName;
if (fullName == null) {
// Initialize the cache on demand. Because this might happen after the type definition gets frozen,
// the initialization must be thread-safe.
if (declaringTypeDefinition != null) {
fullName = declaringTypeDefinition.FullName + "." + this.name;
} else if (string.IsNullOrEmpty(ns)) {
fullName = this.name;
} else {
fullName = this.ns + "." + this.name;
}
this.cachedFullName = fullName;
}
return fullName;
}
}

Loading…
Cancel
Save