[Lldb-commits] [lldb] r209010 - Fix from: Scott Knight(knightsc at gmail.com):

Jim Ingham jingham at apple.com
Fri May 16 12:46:56 PDT 2014


Author: jingham
Date: Fri May 16 14:46:56 2014
New Revision: 209010

URL: http://llvm.org/viewvc/llvm-project?rev=209010&view=rev
Log:
Fix from: Scott Knight(knightsc at gmail.com):

Use a map rather than a vector to store the objects managed by the shared 
cluster since mostly want this for random lookup, so the map is much faster.

Modified:
    lldb/trunk/include/lldb/Utility/SharedCluster.h

Modified: lldb/trunk/include/lldb/Utility/SharedCluster.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Utility/SharedCluster.h?rev=209010&r1=209009&r2=209010&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Utility/SharedCluster.h (original)
+++ lldb/trunk/include/lldb/Utility/SharedCluster.h Fri May 16 14:46:56 2014
@@ -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 @@ public:
     
     ~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 @@ public:
     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 @@ public:
         {
             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 @@ private:
     
     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;
 };





More information about the lldb-commits mailing list