Author: Ebuka Ezike
Date: 2026-07-09T15:15:07+01:00
New Revision: 3c849236aef32acf5b974cf0f69005aad8b196c5

URL: 
https://github.com/llvm/llvm-project/commit/3c849236aef32acf5b974cf0f69005aad8b196c5
DIFF: 
https://github.com/llvm/llvm-project/commit/3c849236aef32acf5b974cf0f69005aad8b196c5.diff

LOG: [NFC][lldb] Simplify Typelist::GetTypeAtIndex (#208411)

Access the index value at constant time and use for range for the
`ForEach` functions.

Added: 
    

Modified: 
    lldb/include/lldb/Symbol/TypeList.h
    lldb/source/Symbol/TypeList.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/include/lldb/Symbol/TypeList.h 
b/lldb/include/lldb/Symbol/TypeList.h
index 71126619ecde7..61faf79dc73c1 100644
--- a/lldb/include/lldb/Symbol/TypeList.h
+++ b/lldb/include/lldb/Symbol/TypeList.h
@@ -34,7 +34,7 @@ class TypeList {
 
   bool Empty() const { return !GetSize(); }
 
-  lldb::TypeSP GetTypeAtIndex(uint32_t idx);
+  lldb::TypeSP GetTypeAtIndex(uint32_t idx) const;
 
   typedef std::vector<lldb::TypeSP> collection;
   typedef llvm::iterator_range<collection::const_iterator> TypeIterable;

diff  --git a/lldb/source/Symbol/TypeList.cpp b/lldb/source/Symbol/TypeList.cpp
index eae2fa4e5757c..6e94cfda0acd0 100644
--- a/lldb/source/Symbol/TypeList.cpp
+++ b/lldb/source/Symbol/TypeList.cpp
@@ -39,36 +39,32 @@ uint32_t TypeList::GetSize() const { return m_types.size(); 
}
 // type lists that are returned for "image dump -t TYPENAME" commands and other
 // simple symbol queries that grab the first result...
 
-TypeSP TypeList::GetTypeAtIndex(uint32_t idx) {
-  iterator pos, end;
-  uint32_t i = idx;
-  assert(i < GetSize() && "Accessing past the end of a TypeList");
-  for (pos = m_types.begin(), end = m_types.end(); pos != end; ++pos) {
-    if (i == 0)
-      return *pos;
-    --i;
-  }
-  return TypeSP();
+TypeSP TypeList::GetTypeAtIndex(uint32_t idx) const {
+  assert(idx < GetSize() && "Accessing past the end of a TypeList");
+
+  if (idx < m_types.size())
+    return m_types[idx];
+  return {};
 }
 
 void TypeList::ForEach(
     std::function<bool(const lldb::TypeSP &type_sp)> const &callback) const {
-  for (auto pos = m_types.begin(), end = m_types.end(); pos != end; ++pos) {
-    if (!callback(*pos))
+  for (const auto &type : m_types) {
+    if (!callback(type))
       break;
   }
 }
 
 void TypeList::ForEach(
     std::function<bool(lldb::TypeSP &type_sp)> const &callback) {
-  for (auto pos = m_types.begin(), end = m_types.end(); pos != end; ++pos) {
-    if (!callback(*pos))
+  for (auto &type : m_types) {
+    if (!callback(type))
       break;
   }
 }
 
 void TypeList::Dump(Stream *s, bool show_context) {
-  for (iterator pos = m_types.begin(), end = m_types.end(); pos != end; ++pos)
-    if (Type *t = pos->get())
-      t->Dump(s, show_context);
+  for (auto &type : m_types)
+    if (type)
+      type->Dump(s, show_context);
 }


        
_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to