[Lldb-commits] [lldb] [lldb] Speed up SymbolContextList::AppendIfUnique (PR #181952)

Augusto Noronha via lldb-commits lldb-commits at lists.llvm.org
Thu Feb 19 07:57:20 PST 2026


================
@@ -1218,42 +1268,62 @@ uint32_t SymbolContextList::AppendIfUnique(const SymbolContextList &sc_list,
 
 bool SymbolContextList::AppendIfUnique(const SymbolContext &sc,
                                        bool merge_symbol_into_function) {
-  collection::iterator pos, end = m_symbol_contexts.end();
-  for (pos = m_symbol_contexts.begin(); pos != end; ++pos) {
-    // Because symbol contexts might first be built without the symbol,
-    // which is then appended later on, compare the symbol contexts taking into
-    // accout that one (or either) of them might not have a symbol yet.
-    if (SymbolContext::CompareConsideringPossiblyNullSymbol(*pos, sc))
+
+  // Look in the set if it's populated, otherwise, fall back to linear scan.
+  if (!m_lookup_set.empty()) {
+    if (m_lookup_set.count(sc))
+      return false;
+  } else if (m_symbol_contexts.size() < kSetThreshold) {
----------------
augusto2112 wrote:

Ok updated it. It does look a lot cleaner. Also by updating to SetVector, which only returns const versions of the element type, I realized that there was potential for a bug where we could mutate any field that we wanted, which would invalidate the hashing key, so I took care of that too.

https://github.com/llvm/llvm-project/pull/181952


More information about the lldb-commits mailing list