mirror of
https://sourceware.org/git/binutils-gdb.git
synced 2025-03-01 13:26:47 +08:00
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>
This commit is contained in:
parent
dead89d276
commit
b096524827
@ -515,26 +515,19 @@ 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;
|
||||
}
|
||||
|
||||
symbol_hash_table.emplace (entry.cu_indices, cpool.size ());
|
||||
entry.index_offset = cpool.size ();
|
||||
/* Newly inserted. */
|
||||
cpool.append_offset (entry.cu_indices.size ());
|
||||
for (const auto index : entry.cu_indices)
|
||||
cpool.append_offset (index);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Now write out the hash table. */
|
||||
std::unordered_map<c_str_view, offset_type, c_str_view_hasher> str_table;
|
||||
|
Loading…
Reference in New Issue
Block a user