[Lldb-commits] [lldb] [lldb][NFC] use llvm::erase_if to remove non matching types (PR #168279)

Ebuka Ezike via lldb-commits lldb-commits at lists.llvm.org
Mon Nov 17 10:35:35 PST 2025


https://github.com/da-viper updated https://github.com/llvm/llvm-project/pull/168279

>From 30777182be60ea93c0e97ac976c957c00c0805df Mon Sep 17 00:00:00 2001
From: Ebuka Ezike <yerimyah1 at gmail.com>
Date: Sun, 16 Nov 2025 17:29:47 +0000
Subject: [PATCH 1/3] [lldb][NFC] use llvm::erase_if to remove non matching
 types

---
 lldb/source/Symbol/Symtab.cpp | 24 ++++++++----------------
 1 file changed, 8 insertions(+), 16 deletions(-)

diff --git a/lldb/source/Symbol/Symtab.cpp b/lldb/source/Symbol/Symtab.cpp
index 6080703998ff2..f13257147d190 100644
--- a/lldb/source/Symbol/Symtab.cpp
+++ b/lldb/source/Symbol/Symtab.cpp
@@ -723,14 +723,10 @@ Symtab::AppendSymbolIndexesWithNameAndType(ConstString symbol_name,
   std::lock_guard<std::recursive_mutex> guard(m_mutex);
 
   if (AppendSymbolIndexesWithName(symbol_name, indexes) > 0) {
-    std::vector<uint32_t>::iterator pos = indexes.begin();
-    while (pos != indexes.end()) {
-      if (symbol_type == eSymbolTypeAny ||
-          m_symbols[*pos].GetType() == symbol_type)
-        ++pos;
-      else
-        pos = indexes.erase(pos);
-    }
+    llvm::erase_if(indexes, [this, symbol_type](uint32_t index) {
+      return symbol_type != eSymbolTypeAny &&
+             m_symbols[index].GetType() != symbol_type;
+    });
   }
   return indexes.size();
 }
@@ -743,14 +739,10 @@ uint32_t Symtab::AppendSymbolIndexesWithNameAndType(
 
   if (AppendSymbolIndexesWithName(symbol_name, symbol_debug_type,
                                   symbol_visibility, indexes) > 0) {
-    std::vector<uint32_t>::iterator pos = indexes.begin();
-    while (pos != indexes.end()) {
-      if (symbol_type == eSymbolTypeAny ||
-          m_symbols[*pos].GetType() == symbol_type)
-        ++pos;
-      else
-        pos = indexes.erase(pos);
-    }
+    llvm::erase_if(indexes, [this, symbol_type](uint32_t index) {
+      return symbol_type != eSymbolTypeAny &&
+             m_symbols[index].GetType() != symbol_type;
+    });
   }
   return indexes.size();
 }

>From 81490fbcfa3f743c07d3ce44303a50ca14e4903d Mon Sep 17 00:00:00 2001
From: Ebuka Ezike <yerimyah1 at gmail.com>
Date: Mon, 17 Nov 2025 18:19:33 +0000
Subject: [PATCH 2/3] [lldb] add review changes

---
 lldb/source/Symbol/Symtab.cpp | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/lldb/source/Symbol/Symtab.cpp b/lldb/source/Symbol/Symtab.cpp
index f13257147d190..f4981cd77be2e 100644
--- a/lldb/source/Symbol/Symtab.cpp
+++ b/lldb/source/Symbol/Symtab.cpp
@@ -722,10 +722,10 @@ Symtab::AppendSymbolIndexesWithNameAndType(ConstString symbol_name,
                                            std::vector<uint32_t> &indexes) {
   std::lock_guard<std::recursive_mutex> guard(m_mutex);
 
-  if (AppendSymbolIndexesWithName(symbol_name, indexes) > 0) {
+  if (AppendSymbolIndexesWithName(symbol_name, indexes) > 0 &&
+      symbol_type != eSymbolTypeAny) {
     llvm::erase_if(indexes, [this, symbol_type](uint32_t index) {
-      return symbol_type != eSymbolTypeAny &&
-             m_symbols[index].GetType() != symbol_type;
+      return m_symbols[index].GetType() != symbol_type;
     });
   }
   return indexes.size();
@@ -738,7 +738,8 @@ uint32_t Symtab::AppendSymbolIndexesWithNameAndType(
   std::lock_guard<std::recursive_mutex> guard(m_mutex);
 
   if (AppendSymbolIndexesWithName(symbol_name, symbol_debug_type,
-                                  symbol_visibility, indexes) > 0) {
+                                  symbol_visibility, indexes) > 0 &&
+      symbol_type != eSymbolTypeAny) {
     llvm::erase_if(indexes, [this, symbol_type](uint32_t index) {
       return symbol_type != eSymbolTypeAny &&
              m_symbols[index].GetType() != symbol_type;

>From 7e98454479f97ecd2d3cea599aded503dd4dc092 Mon Sep 17 00:00:00 2001
From: Ebuka Ezike <yerimyah1 at gmail.com>
Date: Mon, 17 Nov 2025 18:35:09 +0000
Subject: [PATCH 3/3] [lldb] add review changes

---
 lldb/source/Symbol/Symtab.cpp | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/lldb/source/Symbol/Symtab.cpp b/lldb/source/Symbol/Symtab.cpp
index f4981cd77be2e..9964ae492bc00 100644
--- a/lldb/source/Symbol/Symtab.cpp
+++ b/lldb/source/Symbol/Symtab.cpp
@@ -741,8 +741,7 @@ uint32_t Symtab::AppendSymbolIndexesWithNameAndType(
                                   symbol_visibility, indexes) > 0 &&
       symbol_type != eSymbolTypeAny) {
     llvm::erase_if(indexes, [this, symbol_type](uint32_t index) {
-      return symbol_type != eSymbolTypeAny &&
-             m_symbols[index].GetType() != symbol_type;
+      return m_symbols[index].GetType() != symbol_type;
     });
   }
   return indexes.size();



More information about the lldb-commits mailing list