PR 71181 Avoid rehash after reserve

François Dumont frs.dumont@gmail.com
Wed May 25 20:48:00 GMT 2016


On 25/05/2016 16:01, Jonathan Wakely wrote:
> On 22/05/16 17:16 +0200, François Dumont wrote:
>> Hi
>>
>>    To fix 71181 problem I propose to change how we deal with reserve 
>> called with pivot values that is to say prime numbers. Now 
>> _M_next_bkt always return a value higher than the input value. This 
>> way when reverse(97) is called we end up with 199 buckets and so 
>> enough space to store 97 values without rehashing.
>>
>>    I have integrated in this patch several other enhancements on the 
>> same subject. Improvement of _M_next_resize management when reaching 
>> highest bucket number. Remove sentinel value in __prime_list, just 
>> need to limit range when calling lower_bound.
>
> I don't think the change to __prime_list is safe. If you compile some
> code with GCC 5 and then used a libstdc++.so with this change the old
> code would still be looking for the sentinel in the array, and would
> not find it.
>
> I think it would be safe to leave the old __prime_list unchanged (and
> then not need to change anything in tr1/hashtable_policy.h?) and add a
> new array with a different name. Existing code compiled with older
> versions of GCC would still find __prime_list, but the new code would
> use a different array.
>
>

     What about this version ? tr1 mode still limit search range as it 
should to make sure it doesn't need to check lower_bound result. And 
sentinel is only kept for backward compatibility and commented to make 
that clear. Maybe there is a clearer way to express that sentinel can be 
removed on a future version breaking abi ?

François
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 71181.patch
Type: text/x-patch
Size: 2934 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/libstdc++/attachments/20160525/7b13ec62/attachment.bin>


More information about the Libstdc++ mailing list