[PATCH] Make StringMap aware of POD types

Pete Cooper peter_cooper at apple.com
Tue Mar 18 17:30:20 PDT 2014


On Mar 18, 2014, at 11:41 AM, Benjamin Kramer <benny.kra at gmail.com> wrote:

> 
> On 18.03.2014, at 18:57, Pete Cooper <peter_cooper at apple.com> wrote:
> 
>> Hey Ben
>> 
>> Here’s a patch for the new version.  I’ve confirmed what you said that at -O3 this results in ~StringMap() having no loops on POD types and BumpPtrAllocators. 
>> 
>> Ok to commit?
>> diff --git a/include/llvm/ADT/StringMap.h b/include/llvm/ADT/StringMap.h
>> index c48f1ea..0b6efa5 100644
>> --- a/include/llvm/ADT/StringMap.h
>> +++ b/include/llvm/ADT/StringMap.h
>> @@ -387,7 +387,17 @@ public:
>>   }
>> 
>>   ~StringMap() {
>> -    clear();
>> +    // Delete all the elements in the map, but don't reset the elements
>> +    // to default values.  This is a copy of clear(), but avoids unecessary work
>> +    // not required in the destructor.
>> +    if (!empty()) {
>> +      for (unsigned I = 0, E = NumBuckets; I != E; ++I) {
>> +        StringMapEntryBase *&Bucket = TheTable[I];
> 
> One minor nit: We're not changing the value in the bucket anymore, so you can drop the reference & here.
> Patch LGTM.
Well spotted.  Committed with that fix in r204204.

Thanks again for the help on this one.

Pete
> 
> - Ben
> 
>> +        if (Bucket && Bucket != getTombstoneVal()) {
>> +          static_cast<MapEntryTy*>(Bucket)->Destroy(Allocator);
>> +        }





More information about the llvm-commits mailing list