Jelajahi Sumber

Moving ownership of image lists between modules instead of copying them. Saves about 0.5 second on large sizes.

Source commit: cf3d85252fdf17bdcc45c4ee32601b6bfa65cd3d
Martin Prikryl 10 tahun lalu
induk
melakukan
9e8f99c87e
3 mengubah file dengan 32 tambahan dan 7 penghapusan
  1. 3 0
      source/forms/Animations.cpp
  2. 8 0
      source/forms/Glyphs.cpp
  3. 21 7
      source/windows/GUITools.cpp

+ 3 - 0
source/forms/Animations.cpp

@@ -58,6 +58,9 @@ __fastcall TAnimationsModule::TAnimationsModule(TComponent * Owner)
     ScaledModule = new TAnimations96Module(Application);
   }
 
+  // Not really necessary as we never acccess AnimationImages by name
   CopyDataModule(this, ScaledModule);
+
+  AnimationImages = NOT_NULL(dynamic_cast<TPngImageList *>(FindComponent(AnimationImages->Name)));
 }
 //---------------------------------------------------------------------------

+ 8 - 0
source/forms/Glyphs.cpp

@@ -45,6 +45,14 @@ __fastcall TGlyphsModule::TGlyphsModule(TComponent* Owner)
   if (ScaledModule != NULL)
   {
     CopyDataModule(this, ScaledModule);
+
+    // Not all these are accessed by field name, but we copy all for consistency
+    ExplorerImages = NOT_NULL(dynamic_cast<TPngImageList *>(FindComponent(ExplorerImages->Name)));
+    SessionImages = NOT_NULL(dynamic_cast<TPngImageList *>(FindComponent(SessionImages->Name)));
+    QueueImages = NOT_NULL(dynamic_cast<TPngImageList *>(FindComponent(QueueImages->Name)));
+    LogImages = NOT_NULL(dynamic_cast<TPngImageList *>(FindComponent(LogImages->Name)));
+    ButtonImages = NOT_NULL(dynamic_cast<TImageList *>(FindComponent(ButtonImages->Name)));
+    DialogImages = NOT_NULL(dynamic_cast<TPngImageList *>(FindComponent(DialogImages->Name)));
   }
 }
 //---------------------------------------------------------------------------

+ 21 - 7
source/windows/GUITools.cpp

@@ -630,19 +630,33 @@ void __fastcall CopyDataModule(TDataModule * TargetModule, TDataModule * SourceM
 {
   DebugAssert(TargetModule->ComponentCount == SourceModule->ComponentCount);
 
+  typedef std::vector<std::pair<TComponent *, TComponent *> > TComponentPairs;
+  TComponentPairs ComponentPairs;
+
   for (int Index = 0; Index < TargetModule->ComponentCount; Index++)
   {
     TComponent * TargetComponent = TargetModule->Components[Index];
-    TImageList * TargetList = dynamic_cast<TImageList *>(TargetComponent);
-    if (ALWAYS_TRUE(TargetList != NULL))
+    TComponent * SourceComponent = SourceModule->FindComponent(TargetComponent->Name);
+    if (ALWAYS_TRUE(SourceComponent != NULL))
     {
-      TImageList * SourceList = dynamic_cast<TImageList *>(SourceModule->FindComponent(TargetList->Name));
-      if (ALWAYS_TRUE(SourceList != NULL))
-      {
-        CopyImageList(TargetList, SourceList);
-      }
+      ComponentPairs.push_back(std::make_pair(TargetComponent, SourceComponent));
     }
   }
+
+  TComponentPairs::const_iterator Iterator = ComponentPairs.begin();
+  while (Iterator != ComponentPairs.end())
+  {
+    TComponent * TargetComponent = Iterator->first;
+    TComponent * SourceComponent = Iterator->second;
+
+    TargetModule->RemoveComponent(TargetComponent);
+    SourceModule->RemoveComponent(SourceComponent);
+
+    TargetModule->InsertComponent(SourceComponent);
+    SourceModule->InsertComponent(TargetComponent);
+
+    Iterator++;
+  }
 }
 //---------------------------------------------------------------------------
 void __fastcall LoadDialogImage(TImage * Image, const UnicodeString & ImageName)