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

Todd Fiala tfiala at google.com
Thu May 15 09:08:36 PDT 2014


Hey Scott,

Did this ever get reviewed?  The change looks reasonable to me.  Did you
run lldb tests against it?

-Todd


On Mon, May 5, 2014 at 1:27 PM, Scott Knight <knightsc at gmail.com> wrote:

> 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;
>  };
>
> _______________________________________________
> lldb-commits mailing list
> lldb-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/lldb-commits
>
>


-- 
Todd Fiala | Software Engineer | tfiala at google.com | 650-943-3180
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20140515/52373115/attachment.html>


More information about the lldb-commits mailing list