r269717 - Switch from SmallVector to TinyPtrVector for the list of attributes on a declaration. This removes a memory allocation for the common case where the declaration has only one attribute.

Richard Smith via cfe-commits cfe-commits at lists.llvm.org
Tue May 17 13:19:27 PDT 2016


On Tue, May 17, 2016 at 10:17 AM, David Blaikie via cfe-commits <
cfe-commits at lists.llvm.org> wrote:

> On Mon, May 16, 2016 at 3:53 PM, Richard Smith via cfe-commits <
> cfe-commits at lists.llvm.org> wrote:
>
>> Author: rsmith
>> Date: Mon May 16 17:53:19 2016
>> New Revision: 269717
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=269717&view=rev
>> Log:
>> Switch from SmallVector to TinyPtrVector for the list of attributes on a
>> declaration. This removes a memory allocation for the common case where the
>> declaration has only one attribute.
>>
>
> Just out of curiosity - if the SmallVector had a small size of 2, why was
> an allocation done for a single attribute?
>

Err, good question. Turns out I forgot to make the actual allocation-saving
change here -- switching ASTContext::DeclAttrs from storing an allocated
AttrVec* to storing an AttrVec. And that in turn is quite painful because
we expose the AttrVec object to people who might cause DeclAttrs to be
resized. I'll see if it's practical to finish this change, and revert if
not.

Modified:
>>     cfe/trunk/include/clang/AST/AttrIterator.h
>>
>> Modified: cfe/trunk/include/clang/AST/AttrIterator.h
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/AttrIterator.h?rev=269717&r1=269716&r2=269717&view=diff
>>
>> ==============================================================================
>> --- cfe/trunk/include/clang/AST/AttrIterator.h (original)
>> +++ cfe/trunk/include/clang/AST/AttrIterator.h Mon May 16 17:53:19 2016
>> @@ -15,6 +15,7 @@
>>  #define LLVM_CLANG_AST_ATTRITERATOR_H
>>
>>  #include "clang/Basic/LLVM.h"
>> +#include "llvm/ADT/TinyPtrVector.h"
>>  #include <iterator>
>>
>>  namespace clang {
>> @@ -39,8 +40,8 @@ void operator delete[](void *Ptr, const
>>  namespace clang {
>>
>>  /// AttrVec - A vector of Attr, which is how they are stored on the AST.
>> -typedef SmallVector<Attr*, 2> AttrVec;
>> -typedef SmallVector<const Attr*, 2> ConstAttrVec;
>> +typedef llvm::TinyPtrVector<Attr*> AttrVec;
>> +typedef llvm::TinyPtrVector<const Attr*> ConstAttrVec;
>>
>>  /// specific_attr_iterator - Iterates over a subrange of an AttrVec, only
>>  /// providing attributes that are of a specific type.
>>
>>
>> _______________________________________________
>> cfe-commits mailing list
>> cfe-commits at lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>>
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160517/a425f63d/attachment-0001.html>


More information about the cfe-commits mailing list