[Bug libstdc++/96088] Range insertion into unordered_map is less effective than a loop with insertion
fdumont at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Thu Jul 9 06:23:16 GMT 2020
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96088
--- Comment #1 from François Dumont <fdumont at gcc dot gnu.org> ---
The core issue here is that unordered_map key type is std::string while you
insert const char* which explains the temporary.
In f2 you use insert(Pair&&) method so a temporary is generated but then moved
into the container. In f1 we try to check for insertion before generating the
value_type and to do so we use hash<std::string> that generates an additional
temporary.
I'll check if we can be smarter here. A nice improvement would be to change
std::hash<std::string> operator signature to:
size_t
operator()(const string_view& __str) const noexcept
but that's a Standard modification.
More information about the Gcc-bugs
mailing list