Browse Source

implement type-lookup cache to improve performance of Forms Designer - http://community.sharpdevelop.net/forums/t/15914.aspx

4.2
Siegfried Pammer 13 years ago
parent
commit
0596de0f0f
  1. 3
      src/AddIns/DisplayBindings/FormsDesigner/Project/Src/DesignerViewContent.cs
  2. 39
      src/AddIns/DisplayBindings/FormsDesigner/Project/Src/Services/TypeResolutionService.cs

3
src/AddIns/DisplayBindings/FormsDesigner/Project/Src/DesignerViewContent.cs

@ -159,6 +159,9 @@ namespace ICSharpCode.FormsDesigner @@ -159,6 +159,9 @@ namespace ICSharpCode.FormsDesigner
{
LoggingService.Debug("Forms designer: Load " + file.FileName + "; inMasterLoadOperation=" + this.inMasterLoadOperation);
if (this.typeResolutionService != null)
this.typeResolutionService.ClearCaches();
if (inMasterLoadOperation) {
if (this.sourceCodeStorage.ContainsFile(file)) {

39
src/AddIns/DisplayBindings/FormsDesigner/Project/Src/Services/TypeResolutionService.cs

@ -361,6 +361,19 @@ namespace ICSharpCode.FormsDesigner.Services @@ -361,6 +361,19 @@ namespace ICSharpCode.FormsDesigner.Services
return GetType(name, throwOnError, false);
}
#if DEBUG
int count = 0;
#endif
Dictionary<string, Type> typeCache = new Dictionary<string, Type>(StringComparer.Ordinal);
Dictionary<string, Type> typeCacheIgnoreCase = new Dictionary<string, Type>(StringComparer.OrdinalIgnoreCase);
public void ClearCaches()
{
typeCacheIgnoreCase.Clear();
typeCache.Clear();
}
public Type GetType(string name, bool throwOnError, bool ignoreCase)
{
if (name == null || name.Length == 0) {
@ -369,9 +382,19 @@ namespace ICSharpCode.FormsDesigner.Services @@ -369,9 +382,19 @@ namespace ICSharpCode.FormsDesigner.Services
if (IgnoreType(name)) {
return null;
}
if (ignoreCase) {
Type cachedType;
if (typeCacheIgnoreCase.TryGetValue(name, out cachedType))
return cachedType;
} else {
Type cachedType;
if (typeCache.TryGetValue(name, out cachedType))
return cachedType;
}
#if DEBUG
if (!name.StartsWith("System.")) {
LoggingService.Debug("TypeResolutionService: Looking for " + name);
count++;
LoggingService.Debug(count + " TypeResolutionService: Looking for " + name);
}
#endif
try {
@ -436,6 +459,7 @@ namespace ICSharpCode.FormsDesigner.Services @@ -436,6 +459,7 @@ namespace ICSharpCode.FormsDesigner.Services
try {
Type t = asm.GetType(name, false);
if (t != null) {
AddToCache(name, t, ignoreCase);
return t;
}
} catch (FileNotFoundException) {
@ -449,7 +473,7 @@ namespace ICSharpCode.FormsDesigner.Services @@ -449,7 +473,7 @@ namespace ICSharpCode.FormsDesigner.Services
if (throwOnError && type == null)
throw new TypeLoadException(name + " not found by TypeResolutionService");
AddToCache(name, type, ignoreCase);
return type;
} catch (Exception e) {
LoggingService.Error(e);
@ -457,6 +481,17 @@ namespace ICSharpCode.FormsDesigner.Services @@ -457,6 +481,17 @@ namespace ICSharpCode.FormsDesigner.Services
return null;
}
void AddToCache(string name, Type type, bool ignoreCase)
{
if (type == null)
return;
if (ignoreCase) {
typeCacheIgnoreCase.Add(name, type);
} else {
typeCache.Add(name, type);
}
}
public void ReferenceAssembly(AssemblyName name)
{
ICSharpCode.Core.LoggingService.Warn("TODO: Add Assembly reference : " + name);

Loading…
Cancel
Save