public inbox for libabigail@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Let std::unordered_map::operator[] insert keys.
@ 2020-05-05 18:16 Giuliano Procida
  2020-05-13  8:07 ` Matthias Maennich
  2020-05-13  8:54 ` Dodji Seketeli
  0 siblings, 2 replies; 3+ messages in thread
From: Giuliano Procida @ 2020-05-05 18:16 UTC (permalink / raw)
  To: libabigail; +Cc: dodji, kernel-team, gprocida

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 <gprocida@google.com>
---
 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<type_base_sptr> 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 =
-- 
2.26.2.526.g744177e7f7-goog


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-05-13  8:54 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-05 18:16 [PATCH] Let std::unordered_map::operator[] insert keys Giuliano Procida
2020-05-13  8:07 ` Matthias Maennich
2020-05-13  8:54 ` Dodji Seketeli

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).