[lld] r260467 - Reorder code to improve readability. NFC.
David Blaikie via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 10 15:57:18 PST 2016
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/cfddb34c/attachment.html>
More information about the llvm-commits
mailing list