[PATCH] Make StringMap aware of POD types

Benjamin Kramer benny.kra at gmail.com
Tue Mar 18 11:41:57 PDT 2014


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.

- Ben

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




More information about the llvm-commits mailing list