Optimize hashtable allocator

François Dumont frs.dumont@gmail.com
Thu Nov 1 21:03:00 GMT 2012


Attached patch applied.

2012-11-01  François Dumont  <fdumont@gcc.gnu.org>

     * include/bits/hashtable_policy.h (__details::_Before_begin<>):
     New, combine a base node instance and an allocator.
     * include/bits/hashtable.h (_Hashtable<>::_M_node_allocator): Remove.
     (_Hashtable<>::_M_before_begin): Rename into _M_bbegin and type
     modified to __detail::_Before_begin<>.
     (_Hashtable<>::_M_node_allocator()): New, get the node allocator
     part of _M_bbegin.
     (_Hashtable<>::_M_before_begin()): New, get the before begin node
     part of _M_bbegin.
     (_Hashtable<>): Adapt to use latter.

François


On 11/01/2012 12:02 AM, Jonathan Wakely wrote:
> On 31 October 2012 22:46, Marc Glisse wrote:
>> On Wed, 31 Oct 2012, Jonathan Wakely wrote:
>>
>>> On 31 October 2012 22:14, François Dumont wrote:
>>>>      Here is the patch I came to. I use the 'universal reference' like you
>>>> propose but some tests started to fail because I think gcc called it
>>>> instead
>>>> of the move constructor.
>>>
>>> Ah of course.  The defaulted copy/move constructors you added are the
>>> right solution for that.
>>
>> Assuming you never copy a non-const lvalue or a const rvalue. The current
>> use seems ok, I just wanted to mention that it is rather fragile.
> Yes, true.  The code that uses that constructor is entirely under the
> implementation's control so it should be avoidable.
>
> If it's ever a problem we could change the constructor to a
> non-template then explicitly construct it with the right type:
>
>         _M_bbegin(_Node_allocator_type(__a)),
>

-------------- next part --------------
A non-text attachment was scrubbed...
Name: hashtable.patch
Type: text/x-patch
Size: 11041 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/libstdc++/attachments/20121101/256008a0/attachment.bin>


More information about the Libstdc++ mailing list