[cfe-commits] r151255 - /cfe/trunk/lib/AST/CXXInheritance.cpp

Benjamin Kramer benny.kra at googlemail.com
Thu Feb 23 10:40:37 PST 2012


On 23.02.2012, at 19:11, Eli Friedman wrote:

> On Thu, Feb 23, 2012 at 7:18 AM, Benjamin Kramer
> <benny.kra at googlemail.com> wrote:
>> Author: d0k
>> Date: Thu Feb 23 09:18:31 2012
>> New Revision: 151255
>> 
>> URL: http://llvm.org/viewvc/llvm-project?rev=151255&view=rev
>> Log:
>> Unique CXXBasePath decls with the SmallVector/pod_sort/std::unique idiom instead of employing a wasteful std::set.
>> 
>> Modified:
>>    cfe/trunk/lib/AST/CXXInheritance.cpp
>> 
>> Modified: cfe/trunk/lib/AST/CXXInheritance.cpp
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/CXXInheritance.cpp?rev=151255&r1=151254&r2=151255&view=diff
>> ==============================================================================
>> --- cfe/trunk/lib/AST/CXXInheritance.cpp (original)
>> +++ cfe/trunk/lib/AST/CXXInheritance.cpp Thu Feb 23 09:18:31 2012
>> @@ -23,12 +23,15 @@
>>  void CXXBasePaths::ComputeDeclsFound() {
>>   assert(NumDeclsFound == 0 && !DeclsFound &&
>>          "Already computed the set of declarations");
>> -
>> -  std::set<NamedDecl *> Decls;
>> -  for (CXXBasePaths::paths_iterator Path = begin(), PathEnd = end();
>> -       Path != PathEnd; ++Path)
>> -    Decls.insert(*Path->Decls.first);
>> -
>> +
>> +  SmallVector<NamedDecl *, 8> Decls;
>> +  for (paths_iterator Path = begin(), PathEnd = end(); Path != PathEnd; ++Path)
>> +    Decls.push_back(*Path->Decls.first);
>> +
>> +  // Eliminate duplicated decls.
>> +  llvm::array_pod_sort(Decls.begin(), Decls.end());
>> +  std::unique(Decls.begin(), Decls.end());
> 
> Does this usage of std::unique actually do the right thing?  You never
> actually shrink the SmallVector.

No, looks like I forgot the actual idiom here :( Fixed in r151270.

This brings up the question whether this code is actually used, all tests still pass (including the llvm test-suite)

- Ben

> -Eli





More information about the cfe-commits mailing list