[lld] r320070 - Simplify .gnu.hash writing. NFC.

Rafael Avila de Espindola via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 11 13:44:55 PST 2017


David Blaikie <dblaikie at gmail.com> writes:

> On Thu, Dec 7, 2017 at 10:51 AM Rafael Espindola via llvm-commits <
> llvm-commits at lists.llvm.org> wrote:
>
>> Author: rafael
>> Date: Thu Dec  7 10:51:19 2017
>> New Revision: 320070
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=320070&view=rev
>> Log:
>> Simplify .gnu.hash writing. NFC.
>>
>> Modified:
>>     lld/trunk/ELF/SyntheticSections.cpp
>>
>> Modified: lld/trunk/ELF/SyntheticSections.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SyntheticSections.cpp?rev=320070&r1=320069&r2=320070&view=diff
>>
>> ==============================================================================
>> --- lld/trunk/ELF/SyntheticSections.cpp (original)
>> +++ lld/trunk/ELF/SyntheticSections.cpp Thu Dec  7 10:51:19 2017
>> @@ -1750,15 +1750,12 @@ void GnuHashTableSection::writeHashTable
>>    // Write hash buckets. Hash buckets contain indices in the following
>>    // hash value table.
>>    uint32_t *Buckets = reinterpret_cast<uint32_t *>(Buf);
>> -  auto SymI = Symbols.begin();
>> -  for (size_t I = 0; I < NBuckets; ++I) {
>> -    auto NewI = std::find_if(SymI, Symbols.end(), [=](const Entry &Ent) {
>> -      return Ent.BucketIdx == I;
>> -    });
>> -    if (NewI != Symbols.end()) {
>> -      write32(Buckets + I, NewI->Sym->DynsymIndex);
>> -      SymI = NewI;
>> -    }
>> +  uint32_t OldBucket = -1;
>> +  for (auto I = Symbols.begin(), E = Symbols.end(); I != E; ++I) {
>>
>
> Any particular reason this isn't a range-based for loop?

The second loop has been merged with the first one and the first one
needs to know if it is the last element:

bool IsLastInChain = (I + 1) == E || I->BucketIdx != (I + 1)->BucketIdx;

Cheers,
Rafael


More information about the llvm-commits mailing list