浏览代码

LibDebug: Dont copy an AbbreviationEntry every time we retrieve a value

These API's are used in a variety of ways when building the die cache.
Each AbbreviationEntry has vector and other members, so avoid copying
it at all costs.
Brian Gianforcaro 3 年之前
父节点
当前提交
c5cdb6eb4c

+ 6 - 2
Userland/Libraries/LibDebug/Dwarf/AbbreviationsMap.cpp

@@ -66,9 +66,13 @@ void AbbreviationsMap::populate_map()
     }
 }
 
-Optional<AbbreviationsMap::AbbreviationEntry> AbbreviationsMap::get(u32 code) const
+AbbreviationsMap::AbbreviationEntry const* AbbreviationsMap::get(u32 code) const
 {
-    return m_entries.get(code);
+    auto it = m_entries.find(code);
+    if (it == m_entries.end()) {
+        return nullptr;
+    }
+    return &it->value;
 }
 
 }

+ 1 - 3
Userland/Libraries/LibDebug/Dwarf/AbbreviationsMap.h

@@ -20,14 +20,12 @@ public:
     AbbreviationsMap(DwarfInfo const& dwarf_info, u32 offset);
 
     struct AbbreviationEntry {
-
         EntryTag tag;
         bool has_children;
 
         Vector<AttributeSpecification> attribute_specifications;
     };
-
-    Optional<AbbreviationEntry> get(u32 code) const;
+    AbbreviationEntry const* get(u32 code) const;
 
 private:
     void populate_map();

+ 6 - 6
Userland/Libraries/LibDebug/Dwarf/DIE.cpp

@@ -32,13 +32,13 @@ void DIE::rehydrate_from(u32 offset, Optional<u32> parent_offset)
         m_tag = EntryTag::None;
     } else {
         auto abbreviation_info = m_compilation_unit.abbreviations_map().get(m_abbreviation_code);
-        VERIFY(abbreviation_info.has_value());
+        VERIFY(abbreviation_info);
 
-        m_tag = abbreviation_info.value().tag;
-        m_has_children = abbreviation_info.value().has_children;
+        m_tag = abbreviation_info->tag;
+        m_has_children = abbreviation_info->has_children;
 
         // We iterate the attributes data only to calculate this DIE's size
-        for (auto& attribute_spec : abbreviation_info.value().attribute_specifications) {
+        for (auto& attribute_spec : abbreviation_info->attribute_specifications) {
             m_compilation_unit.dwarf_info().get_attribute_value(attribute_spec.form, attribute_spec.value, stream, &m_compilation_unit);
         }
     }
@@ -52,9 +52,9 @@ Optional<AttributeValue> DIE::get_attribute(Attribute const& attribute) const
     stream.discard_or_error(m_data_offset);
 
     auto abbreviation_info = m_compilation_unit.abbreviations_map().get(m_abbreviation_code);
-    VERIFY(abbreviation_info.has_value());
+    VERIFY(abbreviation_info);
 
-    for (const auto& attribute_spec : abbreviation_info.value().attribute_specifications) {
+    for (const auto& attribute_spec : abbreviation_info->attribute_specifications) {
         auto value = m_compilation_unit.dwarf_info().get_attribute_value(attribute_spec.form, attribute_spec.value, stream, &m_compilation_unit);
         if (attribute_spec.attribute == attribute) {
             return value;