[PATCH] D45227: Instead of using std::copy, clear the vector first and add new elements. NFC.

David Blaikie via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 9 13:33:20 PDT 2018


Fair enough (:

On Mon, Apr 9, 2018 at 1:25 PM Rui Ueyama <ruiu at google.com> wrote:

> I think that the new code is easier to read than before, and the
> performance is the same as we reserve space before adding an element?
>
> On Mon, Apr 9, 2018 at 11:41 AM David Blaikie <dblaikie at gmail.com> wrote:
>
>> Out of curiosity - what was the motivation for this change? I'd expect
>> that copy would be faster than repeated push_back (though maybe LLVM can
>> optimize it to match)
>>
>> On Tue, Apr 3, 2018 at 1:00 PM Rui Ueyama via Phabricator via
>> llvm-commits <llvm-commits at lists.llvm.org> wrote:
>>
>>> ruiu created this revision.
>>> ruiu added a reviewer: pcc.
>>> Herald added subscribers: arichardson, emaste.
>>> Herald added a reviewer: espindola.
>>>
>>> Instead of using std::copy, clear the vector first and add new elements.
>>> NFC.
>>>
>>>
>>> https://reviews.llvm.org/D45227
>>>
>>> Files:
>>>   lld/ELF/Writer.cpp
>>>
>>>
>>> Index: lld/ELF/Writer.cpp
>>> ===================================================================
>>> --- lld/ELF/Writer.cpp
>>> +++ lld/ELF/Writer.cpp
>>> @@ -1137,24 +1137,23 @@
>>>    // of the second block of cold code can call the hot code without a
>>> thunk. So
>>>    // we effectively double the amount of code that could potentially
>>> call into
>>>    // the hot code without a thunk.
>>> -  size_t UnorderedInsPt = 0;
>>> +  size_t InsPt = 0;
>>>    if (Target->ThunkSectionSpacing && !OrderedSections.empty()) {
>>>      uint64_t UnorderedPos = 0;
>>> -    for (; UnorderedInsPt != UnorderedSections.size();
>>> ++UnorderedInsPt) {
>>> -      UnorderedPos += UnorderedSections[UnorderedInsPt]->getSize();
>>> +    for (; InsPt != UnorderedSections.size(); ++InsPt) {
>>> +      UnorderedPos += UnorderedSections[InsPt]->getSize();
>>>        if (UnorderedPos > UnorderedSize / 2)
>>>          break;
>>>      }
>>>    }
>>>
>>> -  std::copy(UnorderedSections.begin(),
>>> -            UnorderedSections.begin() + UnorderedInsPt,
>>> ISD->Sections.begin());
>>> -  std::vector<InputSection *>::iterator SectionsPos =
>>> -      ISD->Sections.begin() + UnorderedInsPt;
>>> +  ISD->Sections.clear();
>>> +  for (InputSection *IS : makeArrayRef(UnorderedSections).slice(0,
>>> InsPt))
>>> +    ISD->Sections.push_back(IS);
>>>    for (std::pair<InputSection *, int> P : OrderedSections)
>>> -    *SectionsPos++ = P.first;
>>> -  std::copy(UnorderedSections.begin() + UnorderedInsPt,
>>> UnorderedSections.end(),
>>> -            SectionsPos);
>>> +    ISD->Sections.push_back(P.first);
>>> +  for (InputSection *IS : makeArrayRef(UnorderedSections).slice(InsPt))
>>> +    ISD->Sections.push_back(IS);
>>>  }
>>>
>>>  static void sortSection(OutputSection *Sec,
>>>
>>>
>>> _______________________________________________
>>> llvm-commits mailing list
>>> llvm-commits at lists.llvm.org
>>> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>>>
>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180409/f66a4276/attachment.html>


More information about the llvm-commits mailing list