[lld] r260467 - Reorder code to improve readability. NFC.

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 10 17:18:52 PST 2016


I think this change is at least not negative. Hopefully slightly positive
by showing how we use the first element of the pair early.

On Wed, Feb 10, 2016 at 3:57 PM, David Blaikie <dblaikie at gmail.com> wrote:

>
>
> On Wed, Feb 10, 2016 at 3:43 PM, Rui Ueyama via llvm-commits <
> llvm-commits at lists.llvm.org> wrote:
>
>> Author: ruiu
>> Date: Wed Feb 10 17:43:16 2016
>> New Revision: 260467
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=260467&view=rev
>> Log:
>> Reorder code to improve readability. NFC.
>>
>
> That seems like a strange change for readability - it's pretty canonical
> to write a lambda where it's used, rather naming it only to use it in one
> place anyway...
>
> The idea is to think of functions taking lambdas as somewhat like an
> existing control flow (while, if, etc) - this works particularly well when
> the functor argument is the last one in a call (& clang-format is designed
> for this case) as it was in the original code here.
>
>
>>
>> Modified:
>>     lld/trunk/ELF/OutputSections.cpp
>>
>> Modified: lld/trunk/ELF/OutputSections.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.cpp?rev=260467&r1=260466&r2=260467&view=diff
>>
>> ==============================================================================
>> --- lld/trunk/ELF/OutputSections.cpp (original)
>> +++ lld/trunk/ELF/OutputSections.cpp Wed Feb 10 17:43:16 2016
>> @@ -769,12 +769,12 @@ static int getPriority(StringRef S) {
>>  template <class ELFT> void OutputSection<ELFT>::sortByPriority() {
>>    // Sort sections by priority.
>>    typedef std::pair<int, InputSection<ELFT> *> Pair;
>> +  auto Comp = [](const Pair &A, const Pair &B) { return A.first <
>> B.first; };
>> +
>>    std::vector<Pair> V;
>>    for (InputSection<ELFT> *S : Sections)
>>      V.push_back({getPriority(S->getSectionName()), S});
>> -  std::stable_sort(V.begin(), V.end(), [](const Pair &A, const Pair &B) {
>> -    return A.first < B.first;
>> -  });
>> +  std::stable_sort(V.begin(), V.end(), Comp);
>>    Sections.clear();
>>    for (Pair &P : V)
>>      Sections.push_back(P.second);
>>
>>
>> _______________________________________________
>> 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/20160210/513778dd/attachment.html>


More information about the llvm-commits mailing list