[llvm] r264383 - StringMap: reserve appropriate size when initializing from an initializer list

David Blaikie via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 25 09:01:04 PDT 2016


On Fri, Mar 25, 2016 at 8:59 AM, Mehdi Amini <mehdi.amini at apple.com> wrote:

> It would, it is just hard to write :)
>
> Usually the pattern is that the client side has two statements: 1 for the
> allocation and 1 for the insertion. So you can get the number of buckets
> between the allocation and the insertion, and verify that it is the same
> after. Here everything happens in the constructor...
>

I was thinking you could count the moves - if the initial size is set to
small, you should see a reallocation during the init list ctor execution,
and you should see a bunch of move constructions. With the size set
correctly you shouldn't see any move constructions, only copy constructions
(in either case you should see exactly as many copy constructions as there
are elements in the init list).

At least that's how I'm picturing it.

- Dave


>
> --
> Mehdi
>
> On Mar 25, 2016, at 7:11 AM, David Blaikie <dblaikie at gmail.com> wrote:
>
> Worth a test?
> On Mar 24, 2016 11:02 PM, "Mehdi Amini via llvm-commits" <
> llvm-commits at lists.llvm.org> wrote:
>
>> Author: mehdi_amini
>> Date: Fri Mar 25 00:57:47 2016
>> New Revision: 264383
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=264383&view=rev
>> Log:
>> StringMap: reserve appropriate size when initializing from an initializer
>> list
>>
>> From: Mehdi Amini <mehdi.amini at apple.com>
>>
>> Modified:
>>     llvm/trunk/include/llvm/ADT/StringMap.h
>>
>> Modified: llvm/trunk/include/llvm/ADT/StringMap.h
>> URL:
>> http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/StringMap.h?rev=264383&r1=264382&r2=264383&view=diff
>>
>> ==============================================================================
>> --- llvm/trunk/include/llvm/ADT/StringMap.h (original)
>> +++ llvm/trunk/include/llvm/ADT/StringMap.h Fri Mar 25 00:57:47 2016
>> @@ -233,7 +233,7 @@ public:
>>        Allocator(A) {}
>>
>>    StringMap(std::initializer_list<std::pair<StringRef, ValueTy>> List)
>> -      : StringMapImpl(static_cast<unsigned>(sizeof(MapEntryTy))) {
>> +      : StringMapImpl(List.size(),
>> static_cast<unsigned>(sizeof(MapEntryTy))) {
>>      for (const auto &P : List) {
>>        insert(P);
>>      }
>>
>>
>> _______________________________________________
>> llvm-commits mailing list
>> llvm-commits at lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160325/9edfb940/attachment.html>


More information about the llvm-commits mailing list