[Lldb-commits] [PATCH] D131996: Use a SmallPtrSet rather than a SmallVector in ClusterManager.
Jim Ingham via Phabricator via lldb-commits
lldb-commits at lists.llvm.org
Thu Aug 18 09:34:39 PDT 2022
This revision was automatically updated to reflect the committed changes.
Closed by commit rG33722848fcb5: Use a SmallPtrSet rather than a SmallVector in ClusterManager. (authored by jingham).
Changed prior to commit:
https://reviews.llvm.org/D131996?vs=453127&id=453685#toc
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D131996/new/
https://reviews.llvm.org/D131996
Files:
lldb/include/lldb/Utility/SharedCluster.h
Index: lldb/include/lldb/Utility/SharedCluster.h
===================================================================
--- lldb/include/lldb/Utility/SharedCluster.h
+++ lldb/include/lldb/Utility/SharedCluster.h
@@ -11,7 +11,7 @@
#include "lldb/Utility/LLDBAssert.h"
#include "llvm/ADT/STLExtras.h"
-#include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/SmallPtrSet.h"
#include <memory>
#include <mutex>
@@ -32,15 +32,15 @@
void ManageObject(T *new_object) {
std::lock_guard<std::mutex> guard(m_mutex);
- assert(!llvm::is_contained(m_objects, new_object) &&
- "ManageObject called twice for the same object?");
- m_objects.push_back(new_object);
+ auto ret = m_objects.insert(new_object);
+ assert(ret.second && "ManageObject called twice for the same object?");
}
std::shared_ptr<T> GetSharedPointer(T *desired_object) {
std::lock_guard<std::mutex> guard(m_mutex);
auto this_sp = this->shared_from_this();
- if (!llvm::is_contained(m_objects, desired_object)) {
+ size_t count = m_objects.count(desired_object);
+ if (count == 0) {
lldbassert(false && "object not found in shared cluster when expected");
desired_object = nullptr;
}
@@ -49,8 +49,14 @@
private:
ClusterManager() : m_objects() {}
-
- llvm::SmallVector<T *, 16> m_objects;
+ // The cluster manager is used primarily to manage the
+ // children of root ValueObjects. So it will always have
+ // one element - the root. Pointers will often have dynamic
+ // values, so having 2 entries is pretty common. It's also
+ // pretty common to have small (2,3) structs, so setting the
+ // static size to 4 will cover those cases with no allocations
+ // w/o wasting too much space.
+ llvm::SmallPtrSet<T *, 4> m_objects;
std::mutex m_mutex;
};
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D131996.453685.patch
Type: text/x-patch
Size: 1807 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20220818/eee2b71e/attachment-0001.bin>
More information about the lldb-commits
mailing list