[Lldb-commits] [lldb] 9ed72d4 - [lldb][NFCI] Replace bespoke iterator check with std::next

Alex Langford via lldb-commits lldb-commits at lists.llvm.org
Thu Aug 31 10:57:23 PDT 2023


Author: Alex Langford
Date: 2023-08-31T10:55:00-07:00
New Revision: 9ed72d4d4d507b60a54f6b74e86433f837ded93c

URL: https://github.com/llvm/llvm-project/commit/9ed72d4d4d507b60a54f6b74e86433f837ded93c
DIFF: https://github.com/llvm/llvm-project/commit/9ed72d4d4d507b60a54f6b74e86433f837ded93c.diff

LOG: [lldb][NFCI] Replace bespoke iterator check with std::next

The primary goal of this change is to change `if (pair != *(--m_dict.end()))`
to `if (std::next(iter) != m_dict.end())`. I was experimenting with
changing the underlying type of `m_dict` and found that this was an
issue. Specifically, it assumes that m_dict iterators are bidirectional.
This change should make it so we only need to assume m_dict iterators can move
forward.

Differential Revision: https://reviews.llvm.org/D159150

Added: 
    

Modified: 
    lldb/source/Utility/StructuredData.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/source/Utility/StructuredData.cpp b/lldb/source/Utility/StructuredData.cpp
index c0ed1e5a5c73e4..c870a0eb82b27c 100644
--- a/lldb/source/Utility/StructuredData.cpp
+++ b/lldb/source/Utility/StructuredData.cpp
@@ -228,9 +228,9 @@ void StructuredData::Array::GetDescription(lldb_private::Stream &s) const {
 
 void StructuredData::Dictionary::GetDescription(lldb_private::Stream &s) const {
   size_t indentation_level = s.GetIndentLevel();
-  for (const auto &pair : m_dict) {
+  for (auto iter = m_dict.begin(); iter != m_dict.end(); iter++) {
     // Sanitize.
-    if (pair.first.IsNull() || pair.first.IsEmpty() || !pair.second)
+    if (iter->first.IsNull() || iter->first.IsEmpty() || !iter->second)
       continue;
 
     // Reset original indentation level.
@@ -238,11 +238,11 @@ void StructuredData::Dictionary::GetDescription(lldb_private::Stream &s) const {
     s.Indent();
 
     // Print key.
-    s.Printf("%s:", pair.first.AsCString());
+    s.Printf("%s:", iter->first.AsCString());
 
     // Return to new line and increase indentation if value is record type.
     // Otherwise add spacing.
-    bool should_indent = IsRecordType(pair.second);
+    bool should_indent = IsRecordType(iter->second);
     if (should_indent) {
       s.EOL();
       s.IndentMore();
@@ -251,8 +251,8 @@ void StructuredData::Dictionary::GetDescription(lldb_private::Stream &s) const {
     }
 
     // Print value and new line if now last pair.
-    pair.second->GetDescription(s);
-    if (pair != *(--m_dict.end()))
+    iter->second->GetDescription(s);
+    if (std::next(iter) != m_dict.end())
       s.EOL();
 
     // Reset indentation level if it was incremented previously.


        


More information about the lldb-commits mailing list