[PATCH] PR libstdc++/83709 don't rehash if no insertion
Jonathan Wakely
jwakely@redhat.com
Tue Jan 9 13:06:00 GMT 2018
On 08/01/18 22:31 +0100, François Dumont wrote:
>Hi
>
>Â Â Â Bug confirmed, limited to range insertion on unordered_set and
>unordered_map.
>
>Â Â Â I had to specialize _M_insert_range for those containers. Now this
>method maintains the theoretical number of elements to insert which is
>used only if an insertion takes place.
>
>Â Â Â I also took this oportunity to introduce a small change in
>__distance_fw to report 0 only if __first == __last and do nothing in
>this case.
>
>Â Â Â * include/bits/hashtable_policy.h
>Â Â Â (__distance_fwd(_Iterator, _Iterator, input_iterator_tag)): Return 1 if
>Â Â Â __first != __last.
>Â Â Â (_Insert_base::_M_insert_range(_Ite, _Ite, _NodeGetter,
>true_type)): New.
>Â Â Â (_Insert_base::_M_insert_range(_Ite, _Ite, _NodeGetter, false_type)):
>Â Â Â Add false_type parameter.
>Â Â Â (_Insert_base::insert): Adapt.
>Â Â Â * include/bits/hashtable.h (_Hashtable::operator=(initializzr_list<>)):
>Â Â Â Adapt.
>Â Â Â (_Hashtable::_M_insert_unique_node): Add __n_elt parameter, defaulted
>Â Â Â to 1.
>Â Â Â (_Hashtable::_M_insert(_Arg&&, const _NodeGen&, true_type, size_t)):
>Â Â Â Likewise.
>Â Â Â (_Hashtable::_M_merge_unique): Pass target number of elements to add to
>Â Â Â produce only 1 rehash if necessary.
>Â Â Â * testsuite/23_containers/unordered_map/insert/83709.cc: New.
>Â Â Â * testsuite/23_containers/unordered_set/insert/83709.cc: New.
>
>Tested under Linux x86_64 normal and debug modes.
>
>Ok to commit ?
OK, thanks for the quick fix.
More information about the Libstdc++
mailing list