[PATCH] Make StringMap aware of POD types

Pete Cooper peter_cooper at apple.com
Mon Mar 17 14:18:26 PDT 2014


On Mar 17, 2014, at 1:15 PM, Benjamin Kramer <benny.kra at gmail.com> wrote:

> 
> On 17.03.2014, at 20:38, Chandler Carruth <chandlerc at google.com> wrote:
> 
>> 
>> On Mon, Mar 17, 2014 at 12:32 PM, Pete Cooper <peter_cooper at apple.com> wrote:
>> I was worried about duplication, but actually that might be cleaner.  I’ll give that a try now.
>> 
>> If the duplication is a problem, factor that into a private helper function used by both?
> 
> It can be written in two lines, not worth its own function.
Agreed.
> 
> for (auto &Entry : this)
>  Entry.Destroy(Allocator);
Thanks for this.  Its a nice small snippet.  I tweaked it to this:

    if (!empty()) {
      for (auto &Entry : *this)
        Entry.Destroy(Allocator);

However, this is still about 10% faster


    if (!empty()) {
      for (unsigned I = 0, E = NumBuckets; I != E; ++I) {
        StringMapEntryBase *&Bucket = TheTable[I];
        if (Bucket && Bucket != getTombstoneVal()) {
          static_cast<MapEntryTy*>(Bucket)->Destroy(Allocator);
        }
      }
    }

The problem is that iterator++ isn’t getting optimized out.  Actually neither is the whole loop I gave, but somehow it runs a bit quicker.  I think its failing to inline ++ as it shows up in the trace even on -O3.

Pete
> 
> - Ben

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140317/12124a21/attachment.html>


More information about the llvm-commits mailing list