mirror of
https://github.com/gcc-mirror/gcc.git
synced 2024-11-21 13:40:47 +00:00
a147bfcaf1
I realised that _M_merge_unique and _M_merge_multi call extract(iter) which then has to call _M_get_previous_node to iterate through the bucket to find the node before the one iter points to. Since the merge function is already iterating over the entire container, we had the previous node a moment ago. Walking the whole bucket to find it again is wasteful. We could just rewrite the loop in terms of node pointers instead of iterators, and then call _M_extract_node directly. However, this is only possible when the source container is the same type as the destination, because otherwise we can't access the source's private members (_M_before_begin, _M_begin, _M_extract_node etc.) Add overloads of _M_merge_unique and _M_merge_multi that work with source containers of the same type, to enable this optimization. For both overloads of _M_merge_unique we can also remove the conditional modifications to __n_elt and just consistently decrement it for every element processed. Use a multiplier of one or zero that dictates whether __n_elt is passed to _M_insert_unique_node or not. We can also remove the repeated calls to size() and just keep track of the size in a local variable. Although _M_merge_unique and _M_merge_multi should be safe for "self-merge", i.e. when doing c.merge(c), it's wasteful to search/insert every element when we don't need to do anything. Add 'this == &source' checks to the overloads taking an lvalue of the container's own type. Because those checks aren't needed for the rvalue overloads, change those to call the underlying _M_merge_xxx function directly instead of going through the lvalue overload that checks the address. I've also added more extensive tests for better coverage of the new overloads added in this commit. libstdc++-v3/ChangeLog: * include/bits/hashtable.h (_M_merge_unique): Add overload for merging from same type. (_M_merge_unique<Compatible>): Simplify size tracking. Add comment. (_M_merge_multi): Add overload for merging from same type. (_M_merge_multi<Compatible>): Add comment. * include/bits/unordered_map.h (unordered_map::merge): Check for self-merge in the lvalue overload. Call _M_merge_unique directly for the rvalue overload. (unordered_multimap::merge): Likewise. * include/bits/unordered_set.h (unordered_set::merge): Likewise. (unordered_multiset::merge): Likewise. * testsuite/23_containers/unordered_map/modifiers/merge.cc: Add more tests. * testsuite/23_containers/unordered_multimap/modifiers/merge.cc: Likewise. * testsuite/23_containers/unordered_multiset/modifiers/merge.cc: Likewise. * testsuite/23_containers/unordered_set/modifiers/merge.cc: Likewise. |
||
---|---|---|
.. | ||
config | ||
doc | ||
include | ||
libsupc++ | ||
po | ||
python | ||
scripts | ||
src | ||
testsuite | ||
.editorconfig | ||
acinclude.m4 | ||
aclocal.m4 | ||
ChangeLog | ||
ChangeLog-1998 | ||
ChangeLog-1999 | ||
ChangeLog-2000 | ||
ChangeLog-2001 | ||
ChangeLog-2002 | ||
ChangeLog-2003 | ||
ChangeLog-2004 | ||
ChangeLog-2005 | ||
ChangeLog-2006 | ||
ChangeLog-2007 | ||
ChangeLog-2008 | ||
ChangeLog-2009 | ||
ChangeLog-2010 | ||
ChangeLog-2011 | ||
ChangeLog-2012 | ||
ChangeLog-2013 | ||
ChangeLog-2014 | ||
ChangeLog-2015 | ||
ChangeLog-2016 | ||
ChangeLog-2017 | ||
ChangeLog-2018 | ||
ChangeLog-2019 | ||
ChangeLog-2020 | ||
ChangeLog-2021 | ||
ChangeLog-2022 | ||
ChangeLog-2023 | ||
config.h.in | ||
configure | ||
configure.ac | ||
configure.host | ||
crossconfig.m4 | ||
fragment.am | ||
linkage.m4 | ||
Makefile.am | ||
Makefile.in | ||
README |
file: libstdc++-v3/README New users may wish to point their web browsers to the file index.html in the 'doc/html' subdirectory. It contains brief building instructions and notes on how to configure the library in interesting ways.