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

don hinton via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 25 09:02:21 PDT 2016


Ah, I remembered seeing your changes to DenseMap, but missed the ones to
StringMap.


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

> Hi Don,
>
> You may want to look at the series of changes I committed to StringMap and
> DenseMap.
>
> The StringMapImpl constructor looks like this now:
>
> StringMapImpl::StringMapImpl(unsigned InitSize, unsigned itemSize) {
>   ItemSize = itemSize;
>
>
>   // If a size is specified, initialize the table with that many buckets.
>   if (InitSize) {
>     // The table will grow when the number of entries reach 3/4 of the
> number of
>     // buckets. To guarantee that "InitSize" number of entries can be
> inserted
>     // in the table without growing, we allocate just what is needed here.
>     init(getMinBucketToReserveForEntries(InitSize));
>     return;
>   }
>
> I hope this address your concern.
>
> --
> Mehdi
>
>
> On Mar 25, 2016, at 7:39 AM, don hinton <hintonda at gmail.com> wrote:
>
> Won't this still force a rehash since the table will be more that 3/4
> full?  Assuming the initialization list contains unique keys.
> On Mar 25, 2016 10:11 AM, "David Blaikie via llvm-commits" <
> llvm-commits at lists.llvm.org> 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
>>>
>>
>> _______________________________________________
>> 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/640a6e4d/attachment.html>


More information about the llvm-commits mailing list