From patchwork Tue May 5 18:16:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Giuliano Procida X-Patchwork-Id: 39224 From: gprocida@google.com (Giuliano Procida) Date: Tue, 5 May 2020 19:16:18 +0100 Subject: [PATCH] Let std::unordered_map::operator[] insert keys. Message-ID: <20200505181618.238776-1-gprocida@google.com> This patch replaces some verbose code with one-liners that rely on std::unordered_map::operator[] to insert a missing key and return a reference to the default-constructed inserted value. * src/abg-reader.cc (read_context::key_type_decl): Rely on std::unordered_map::operator[] to create map entries if they are missing. (build_elf_symbol_db): Ditto. Signed-off-by: Giuliano Procida Reviewed-by: Matthias Maennich Acked-by: Dodji Seketeli --- src/abg-reader.cc | 22 ++-------------------- 1 file changed, 2 insertions(+), 20 deletions(-) diff --git a/src/abg-reader.cc b/src/abg-reader.cc index 5583a31c..69f7c311 100644 --- a/src/abg-reader.cc +++ b/src/abg-reader.cc @@ -556,17 +556,7 @@ public: if (!type) return false; - type_base_sptr t = type; - - types_map_it i = m_types_map.find(id); - if (i != m_types_map.end()) - i->second.push_back(type); - else - { - vector types; - types.push_back(type); - m_types_map[id] = types; - } + m_types_map[id].push_back(type); return true; } @@ -2882,15 +2872,7 @@ build_elf_symbol_db(read_context& ctxt, for (string_elf_symbol_sptr_map_type::const_iterator i = id_sym_map.begin(); i != id_sym_map.end(); ++i) - { - it = map->find(i->second->get_name()); - if (it == map->end()) - { - (*map)[i->second->get_name()] = elf_symbols(); - it = map->find(i->second->get_name()); - } - it->second.push_back(i->second); - } + (*map)[i->second->get_name()].push_back(i->second); // Now build the alias relations for (xml_node_ptr_elf_symbol_sptr_map_type::const_iterator x =