[Lldb-commits] [lldb] 7611c5b - [nfc] [lldb] Refactor DWARFUnit::GetDIE

Jan Kratochvil via lldb-commits lldb-commits at lists.llvm.org
Mon Oct 26 15:18:37 PDT 2020


Author: Jan Kratochvil
Date: 2020-10-26T23:18:19+01:00
New Revision: 7611c5bb42a96c13d0e53ade546633bf9ed56f0c

URL: https://github.com/llvm/llvm-project/commit/7611c5bb42a96c13d0e53ade546633bf9ed56f0c
DIFF: https://github.com/llvm/llvm-project/commit/7611c5bb42a96c13d0e53ade546633bf9ed56f0c.diff

LOG: [nfc] [lldb] Refactor DWARFUnit::GetDIE

Reduce indentation of the code by early returns for failed code paths.

Added: 
    

Modified: 
    lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
index 5da23e7c89f1..12e8b25130a9 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
@@ -525,21 +525,23 @@ static bool CompareDIEOffset(const DWARFDebugInfoEntry &die,
 // DIE from this compile unit. Otherwise we grab the DIE from the DWARF file.
 DWARFDIE
 DWARFUnit::GetDIE(dw_offset_t die_offset) {
-  if (die_offset != DW_INVALID_OFFSET) {
-    if (ContainsDIEOffset(die_offset)) {
-      ExtractDIEsIfNeeded();
-      DWARFDebugInfoEntry::const_iterator end = m_die_array.cend();
-      DWARFDebugInfoEntry::const_iterator pos =
-          lower_bound(m_die_array.cbegin(), end, die_offset, CompareDIEOffset);
-      if (pos != end) {
-        if (die_offset == (*pos).GetOffset())
-          return DWARFDIE(this, &(*pos));
-      }
-    } else
-      GetSymbolFileDWARF().GetObjectFile()->GetModule()->ReportError(
-          "GetDIE for DIE 0x%" PRIx32 " is outside of its CU 0x%" PRIx32,
-          die_offset, GetOffset());
+  if (die_offset == DW_INVALID_OFFSET)
+    return DWARFDIE(); // Not found
+
+  if (!ContainsDIEOffset(die_offset)) {
+    GetSymbolFileDWARF().GetObjectFile()->GetModule()->ReportError(
+        "GetDIE for DIE 0x%" PRIx32 " is outside of its CU 0x%" PRIx32,
+        die_offset, GetOffset());
+    return DWARFDIE(); // Not found
   }
+
+  ExtractDIEsIfNeeded();
+  DWARFDebugInfoEntry::const_iterator end = m_die_array.cend();
+  DWARFDebugInfoEntry::const_iterator pos =
+      lower_bound(m_die_array.cbegin(), end, die_offset, CompareDIEOffset);
+
+  if (pos != end && die_offset == (*pos).GetOffset())
+    return DWARFDIE(this, &(*pos));
   return DWARFDIE(); // Not found
 }
 


        


More information about the lldb-commits mailing list