diff --git a/lldb/include/lldb/Utility/SharedCluster.h b/lldb/include/lldb/Utility/SharedCluster.h --- a/lldb/include/lldb/Utility/SharedCluster.h +++ b/lldb/include/lldb/Utility/SharedCluster.h @@ -12,7 +12,8 @@ #include "lldb/Utility/LLDBAssert.h" #include "lldb/Utility/SharingPtr.h" -#include "llvm/ADT/SmallPtrSet.h" +#include "llvm/ADT/STLExtras.h" +#include "llvm/ADT/SmallVector.h" #include @@ -42,12 +43,8 @@ ClusterManager() : m_objects(), m_external_ref(0), m_mutex() {} ~ClusterManager() { - for (typename llvm::SmallPtrSet::iterator pos = m_objects.begin(), - end = m_objects.end(); - pos != end; ++pos) { - T *object = *pos; - delete object; - } + for (T *obj : m_objects) + delete obj; // Decrement refcount should have been called on this ClusterManager, and // it should have locked the mutex, now we will unlock it before we destroy @@ -57,14 +54,16 @@ void ManageObject(T *new_object) { std::lock_guard guard(m_mutex); - m_objects.insert(new_object); + assert(!llvm::is_contained(m_objects, new_object) && + "ManageObject called twice for the same object?"); + m_objects.push_back(new_object); } typename lldb_private::SharingPtr GetSharedPointer(T *desired_object) { { std::lock_guard guard(m_mutex); m_external_ref++; - if (0 == m_objects.count(desired_object)) { + if (!llvm::is_contained(m_objects, desired_object)) { lldbassert(false && "object not found in shared cluster when expected"); desired_object = nullptr; } @@ -85,7 +84,7 @@ friend class imp::shared_ptr_refcount; - llvm::SmallPtrSet m_objects; + llvm::SmallVector m_objects; int m_external_ref; std::mutex m_mutex; };