Browse Source

Improve slot performance for framework listeners by tuning the hash value.

Sascha Zelzer 12 years ago
parent
commit
ee1d93ff89

+ 9 - 2
Libs/PluginFramework/ctkServiceSlotEntry.cpp

@@ -37,7 +37,8 @@ public:
   ctkServiceSlotEntryData(QSharedPointer<ctkPlugin> p, QObject* receiver,
                           const char* slot)
     : plugin(p), receiver(receiver),
-      slot(slot), removed(false)
+      slot(slot), removed(false),
+      hashValue(0)
   {
 
   }
@@ -69,6 +70,7 @@ public:
   const char* slot;
   bool removed;
 
+  uint hashValue;
 };
 
 //----------------------------------------------------------------------------
@@ -171,5 +173,10 @@ ctkLDAPExpr::LocalCache& ctkServiceSlotEntry::getLocalCache() const
 //----------------------------------------------------------------------------
 uint qHash(const ctkServiceSlotEntry& serviceSlot)
 {
-  return qHash(serviceSlot.getPlugin());
+  if (serviceSlot.d->hashValue == 0)
+  {
+    serviceSlot.d->hashValue = qHash(serviceSlot.d->plugin) * 4 +
+        qHash(serviceSlot.d->receiver) * 2 + qHash(serviceSlot.d->slot);
+  }
+  return serviceSlot.d->hashValue;
 }

+ 2 - 0
Libs/PluginFramework/ctkServiceSlotEntry_p.h

@@ -80,6 +80,8 @@ public:
 
 private:
 
+  friend uint qHash(const ctkServiceSlotEntry& serviceSlot);
+
   QExplicitlySharedDataPointer<ctkServiceSlotEntryData> d;
 
 };