diff options
author | Tom Tromey <tom@tromey.com> | 2023-10-15 12:15:36 -0600 |
---|---|---|
committer | Tom Tromey <tom@tromey.com> | 2023-11-29 14:29:44 -0700 |
commit | b096524827460d2a3a7e7d08ae6c2f41a1388bab (patch) | |
tree | 98eeb653b6f5bfc21e8084471a8e8e50b943c23f | |
parent | dead89d27645c391b62da24a2f2942fb8a819d45 (diff) | |
download | gdb-b096524827460d2a3a7e7d08ae6c2f41a1388bab.zip gdb-b096524827460d2a3a7e7d08ae6c2f41a1388bab.tar.gz gdb-b096524827460d2a3a7e7d08ae6c2f41a1388bab.tar.bz2 |
Use try_emplace in index-write.c
index-write.c has a comment indicating that C++17's try_emplace could
be used. This patch makes the change.
Approved-By: Pedro Alves <pedro@palves.net>
-rw-r--r-- | gdb/dwarf2/index-write.c | 25 |
1 files changed, 9 insertions, 16 deletions
diff --git a/gdb/dwarf2/index-write.c b/gdb/dwarf2/index-write.c index b77f4f9..b4a0117 100644 --- a/gdb/dwarf2/index-write.c +++ b/gdb/dwarf2/index-write.c @@ -515,24 +515,17 @@ write_hash_table (mapped_symtab *symtab, data_buf &output, data_buf &cpool) continue; gdb_assert (entry.index_offset == 0); - /* Finding before inserting is faster than always trying to - insert, because inserting always allocates a node, does the - lookup, and then destroys the new node if another node - already had the same key. C++17 try_emplace will avoid - this. */ - const auto found - = symbol_hash_table.find (entry.cu_indices); - if (found != symbol_hash_table.end ()) + auto [iter, inserted] + = symbol_hash_table.try_emplace (entry.cu_indices, + cpool.size ()); + entry.index_offset = iter->second; + if (inserted) { - entry.index_offset = found->second; - continue; + /* Newly inserted. */ + cpool.append_offset (entry.cu_indices.size ()); + for (const auto index : entry.cu_indices) + cpool.append_offset (index); } - - symbol_hash_table.emplace (entry.cu_indices, cpool.size ()); - entry.index_offset = cpool.size (); - cpool.append_offset (entry.cu_indices.size ()); - for (const auto index : entry.cu_indices) - cpool.append_offset (index); } } |