https://github.com/felipepiovezan created 
https://github.com/llvm/llvm-project/pull/74523

The function FindDefinitionTypeForDWARFDeclContext loops over all DIEs 
corresponding to types with a certain name and compares the context of each 
found DIE with the context of a target DIE. However, the target DIE never 
changes throughout this search, and yet we recompute its DeclContext on every 
iteration of the search. This is wasteful because the method is not exactly 
free (see DWARFDebugInfoEntry::GetDWARFDeclContextStatic).

>From f101f4386e9d164b654f0a2176c228e9debb2a47 Mon Sep 17 00:00:00 2001
From: Felipe de Azevedo Piovezan <fpiove...@apple.com>
Date: Thu, 19 Oct 2023 13:45:09 -0700
Subject: [PATCH] [lldb][SymbolFileDWARF][NFC] Remove unnecessary calls to
 GetDWARFDeclContext

The function FindDefinitionTypeForDWARFDeclContext loops over all DIEs
corresponding to types with a certain name and compares the context of each
found DIE with the context of a target DIE. However, the target DIE never
changes throughout this search, and yet we recompute its DeclContext on every
iteration of the search. This is wasteful because the method is not exactly free
(see DWARFDebugInfoEntry::GetDWARFDeclContextStatic).
---
 lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp 
b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
index 142d092e6d2ee..d4cc26a3c329b 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
@@ -3120,7 +3120,8 @@ 
SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(const DWARFDIE &die) {
         template_params = dwarf_ast->GetDIEClassTemplateParams(die);
     }
 
-    m_index->GetTypes(GetDWARFDeclContext(die), [&](DWARFDIE type_die) {
+    const DWARFDeclContext die_dwarf_decl_ctx = GetDWARFDeclContext(die);
+    m_index->GetTypes(die_dwarf_decl_ctx, [&](DWARFDIE type_die) {
       // Make sure type_die's language matches the type system we are
       // looking for. We don't want to find a "Foo" type from Java if we
       // are looking for a "Foo" type for C, C++, ObjC, or ObjC++.
@@ -3184,7 +3185,7 @@ 
SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(const DWARFDIE &die) {
       }
 
       // Make sure the decl contexts match all the way up
-      if (GetDWARFDeclContext(die) != type_dwarf_decl_ctx)
+      if (die_dwarf_decl_ctx != type_dwarf_decl_ctx)
         return true;
 
       Type *resolved_type = ResolveType(type_die, false);

_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to