[PATCH] D18154: DenseMap: make .resize() do the intuitive thing

David Blaikie via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 14 13:48:33 PDT 2016


On Mon, Mar 14, 2016 at 1:40 PM, <escha at apple.com> wrote:

>
> On Mar 14, 2016, at 1:34 PM, David Blaikie <dblaikie at gmail.com> wrote:
>
>
>
> On Mon, Mar 14, 2016 at 1:31 PM, escha via llvm-commits <
> llvm-commits at lists.llvm.org> wrote:
>
>> escha updated this revision to Diff 50637.
>> escha added a comment.
>>
>> Added a test to make sure that resizing is enough to insert N elements
>> without reallocation for a variety of sizes.
>>
>> I also looked quickly over the uses and none of the uses seem to be
>> already-compensating for this.
>>
>>
>> Repository:
>>   rL LLVM
>>
>> http://reviews.llvm.org/D18154
>>
>> Files:
>>   include/llvm/ADT/DenseMap.h
>>   unittests/ADT/DenseMapTest.cpp
>>
>> Index: unittests/ADT/DenseMapTest.cpp
>> ===================================================================
>> --- unittests/ADT/DenseMapTest.cpp
>> +++ unittests/ADT/DenseMapTest.cpp
>> @@ -339,6 +339,19 @@
>>    EXPECT_TRUE(cit == cit2);
>>  }
>>
>> +// Make sure resize actually gives us enough buckets to insert N items
>> +// without increasing allocation size.
>> +TEST(DenseMapCustomTest, ResizeTest) {
>> +  for (unsigned Size = 16; Size < 32; ++Size) {
>> +    DenseMap<unsigned, unsigned> Map;
>> +    Map.resize(Size);
>> +    unsigned MemorySize = Map.getMemorySize();
>> +    for (unsigned i = 0; i < Size; ++i)
>> +      Map[i] = i;
>> +    EXPECT_TRUE(Map.getMemorySize() == MemorySize);
>>
>
> This is probably sufficient (just checking that the size didn't change) -
> but in case it's of interest, I was thinking of a unit test with a
> move-or-copy-counting object in the key or value of the map, then checking
> no extra moves-or-copies occur.
>
>
> I have to admit this is probably beyond my C++ knowledge/abilities to do!
>

No worries


>
> — escha
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160314/069c45e2/attachment.html>


More information about the llvm-commits mailing list