Changeset 10497


Ignore:
Timestamp:
02/21/14 14:00:43 (6 years ago)
Author:
gkronber
Message:

#1972: workaround to improve performance of type selector (the problem is that imagelist methods are SLOW)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Core.Views/3.3/TypeSelector.cs

    r9456 r10497  
    112112        typesTreeView.Nodes.Clear();
    113113        treeNodes.Clear();
     114
    114115        imageList.Images.Clear();
    115116        imageList.Images.Add(HeuristicLab.Common.Resources.VSImageLibrary.Class);      // default icon
     
    117118        imageList.Images.Add(HeuristicLab.Common.Resources.VSImageLibrary.Interface);  // interfaces
    118119        imageList.Images.Add(HeuristicLab.Common.Resources.VSImageLibrary.Template);   // generic types
     120        // additional dictionary for image indexes as imageList.ContainsKey and imageList.IndexOfKey are very slow!
     121        var imageNames = new Dictionary<string, int>();
    119122
    120123        var plugins = from p in ApplicationManager.Manager.Plugins
     
    141144              if (type.IsInterface) typeNode.ImageIndex = 2;
    142145              else if (type.ContainsGenericParameters) typeNode.ImageIndex = 3;
    143               else if (imageList.Images.ContainsKey(type.FullName)) typeNode.ImageIndex = imageList.Images.IndexOfKey(type.FullName);
     146              else if (imageNames.ContainsKey(type.FullName)) typeNode.ImageIndex = imageNames[type.FullName];
    144147              else {
    145148                var image = ItemAttribute.GetImage(type);
    146149                if (image != null) {
    147                   imageList.Images.Add(type.FullName, image);
    148                   typeNode.ImageIndex = imageList.Images.IndexOfKey(type.FullName);
     150                  imageList.Images.Add(image);
     151                  typeNode.ImageIndex = imageList.Images.Count - 1;
     152                  imageNames.Add(type.FullName, imageList.Images.Count - 1);
    149153                }
    150154              }
Note: See TracChangeset for help on using the changeset viewer.