diff options
author | Brian Gianforcaro <bgianf@serenityos.org> | 2021-09-17 02:22:34 -0700 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-09-18 21:05:13 +0200 |
commit | c5cdb6eb4c7a5fa0f742c7c8bdabc39873a4ecbf (patch) | |
tree | 5325e89d51e1cf5ad177869e9392b230cb17799d /Userland | |
parent | 952441943fd2600bc666a3b5455e7b04d87484cd (diff) | |
download | serenity-c5cdb6eb4c7a5fa0f742c7c8bdabc39873a4ecbf.zip |
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.
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/Libraries/LibDebug/Dwarf/AbbreviationsMap.cpp | 8 | ||||
-rw-r--r-- | Userland/Libraries/LibDebug/Dwarf/AbbreviationsMap.h | 4 | ||||
-rw-r--r-- | Userland/Libraries/LibDebug/Dwarf/DIE.cpp | 12 |
3 files changed, 13 insertions, 11 deletions
diff --git a/Userland/Libraries/LibDebug/Dwarf/AbbreviationsMap.cpp b/Userland/Libraries/LibDebug/Dwarf/AbbreviationsMap.cpp index ed5ad5ad03..5cd2e4f4b3 100644 --- a/Userland/Libraries/LibDebug/Dwarf/AbbreviationsMap.cpp +++ b/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; } } diff --git a/Userland/Libraries/LibDebug/Dwarf/AbbreviationsMap.h b/Userland/Libraries/LibDebug/Dwarf/AbbreviationsMap.h index f1a5459c73..9b5cb74334 100644 --- a/Userland/Libraries/LibDebug/Dwarf/AbbreviationsMap.h +++ b/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(); diff --git a/Userland/Libraries/LibDebug/Dwarf/DIE.cpp b/Userland/Libraries/LibDebug/Dwarf/DIE.cpp index 1adabbd21c..76af73aa6e 100644 --- a/Userland/Libraries/LibDebug/Dwarf/DIE.cpp +++ b/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; |