[llvm-commits] [llvm] r153949 - /llvm/trunk/lib/VMCore/Metadata.cpp

Bill Wendling isanbard at gmail.com
Tue Apr 3 04:13:45 PDT 2012


On Apr 3, 2012, at 3:57 AM, Benjamin Kramer wrote:

> On 03.04.2012, at 12:50, Bill Wendling wrote:
> 
>> Author: void
>> Date: Tue Apr  3 05:50:09 2012
>> New Revision: 153949
>> 
>> URL: http://llvm.org/viewvc/llvm-project?rev=153949&view=rev
>> Log:
>> Reserve space for the eventual filling of the vector. This gives a small speedup.
>> 
>> Modified:
>>   llvm/trunk/lib/VMCore/Metadata.cpp
>> 
>> Modified: llvm/trunk/lib/VMCore/Metadata.cpp
>> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Metadata.cpp?rev=153949&r1=153948&r2=153949&view=diff
>> ==============================================================================
>> --- llvm/trunk/lib/VMCore/Metadata.cpp (original)
>> +++ llvm/trunk/lib/VMCore/Metadata.cpp Tue Apr  3 05:50:09 2012
>> @@ -551,17 +551,16 @@
>>         getContext().pImpl->MetadataStore.count(this) &&
>>         "Shouldn't have called this");
>>  const LLVMContextImpl::MDMapTy &Info =
>> -  getContext().pImpl->MetadataStore.find(this)->second;
>> +    getContext().pImpl->MetadataStore.find(this)->second;
>>  assert(!Info.empty() && "Shouldn't have called this");
>> -  
>> +  Result.reserve(Info.size());
>>  Result.append(Info.begin(), Info.end());
> 
> SmallVector::append should grow the vector only once with the exact size, making the reserve call unnecessary. If it grows more than once that's a bug in SmallVector.
> 
That's true, but it uses the "std::distance" function, which in its most primitive form increments through the list to the end. While it's possible for SmallVector to be a subtraction between two addresses.

-bw






More information about the llvm-commits mailing list