[Lldb-commits] [PATCH] Use SmallPtrSet in ClusterManager

Scott Knight knightsc at gmail.com
Mon May 5 13:27:14 PDT 2014


Based on conversations with Greg and Jim on lldb-dev, when lldb looks a a root object with many sub objects the ClusterManager can get slower and slower. This change switches the internal object list from a vector to the SmallPtrSet data type which speeds things up.

http://reviews.llvm.org/D3616

Files:
  include/lldb/Utility/SharedCluster.h

Index: include/lldb/Utility/SharedCluster.h
===================================================================
--- include/lldb/Utility/SharedCluster.h
+++ include/lldb/Utility/SharedCluster.h
@@ -13,6 +13,8 @@
 #include "lldb/Utility/SharingPtr.h"
 #include "lldb/Host/Mutex.h"
 
+#include "llvm/ADT/SmallPtrSet.h"
+
 namespace lldb_private {
 
 namespace imp
@@ -50,11 +52,12 @@
     
     ~ClusterManager ()
     {
-        size_t n_items = m_objects.size();
-        for (size_t i = 0; i < n_items; i++)
+        for (typename llvm::SmallPtrSet<T *, 16>::iterator pos = m_objects.begin(), end = m_objects.end(); pos != end; ++pos)
         {
-            delete m_objects[i];
+            T *object = *pos;
+            delete object;
         }
+
         // Decrement refcount should have been called on this ClusterManager,
         // and it should have locked the mutex, now we will unlock it before
         // we destroy it...
@@ -64,8 +67,7 @@
     void ManageObject (T *new_object)
     {
         Mutex::Locker locker (m_mutex);
-        if (!ContainsObject(new_object))
-            m_objects.push_back (new_object);
+        m_objects.insert (new_object);
     }
     
     typename lldb_private::SharingPtr<T> GetSharedPointer(T *desired_object)
@@ -73,20 +75,13 @@
         {
             Mutex::Locker locker (m_mutex);
             m_external_ref++;
-            assert (ContainsObject(desired_object));
+            assert (m_objects.count(desired_object));
         }
         return typename lldb_private::SharingPtr<T> (desired_object, new imp::shared_ptr_refcount<ClusterManager> (this));
     }
     
 private:
     
-    bool ContainsObject (const T *desired_object)
-    {
-        typename std::vector<T *>::iterator pos, end = m_objects.end();
-        pos = std::find(m_objects.begin(), end, desired_object);
-        return pos != end;
-    }
-    
     void DecrementRefCount () 
     {
         m_mutex.Lock();
@@ -99,7 +94,7 @@
     
     friend class imp::shared_ptr_refcount<ClusterManager>;
     
-    std::vector<T *> m_objects;
+    llvm::SmallPtrSet<T *, 16> m_objects;
     int m_external_ref;
     Mutex m_mutex;
 };
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D3616.9086.patch
Type: text/x-patch
Size: 2161 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20140505/9608685d/attachment.bin>


More information about the lldb-commits mailing list