[lld] 4d4d6eb - [ELF] findOrphanPos: avoid redundant getRankProximity call. NFC
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Fri May 31 20:26:00 PDT 2024
Author: Fangrui Song
Date: 2024-05-31T20:25:56-07:00
New Revision: 4d4d6eb6e8b519fec7ca5b689762bb964a7ce186
URL: https://github.com/llvm/llvm-project/commit/4d4d6eb6e8b519fec7ca5b689762bb964a7ce186
DIFF: https://github.com/llvm/llvm-project/commit/4d4d6eb6e8b519fec7ca5b689762bb964a7ce186.diff
LOG: [ELF] findOrphanPos: avoid redundant getRankProximity call. NFC
Added:
Modified:
lld/ELF/Writer.cpp
Removed:
################################################################################
diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp
index c2ccc4f49ad2e..05f2e95def4b3 100644
--- a/lld/ELF/Writer.cpp
+++ b/lld/ELF/Writer.cpp
@@ -936,17 +936,22 @@ findOrphanPos(SmallVectorImpl<SectionCommand *>::iterator b,
}
// Find the first element that has as close a rank as possible.
- auto i = std::max_element(b, e, [=](SectionCommand *a, SectionCommand *b) {
- return getRankProximity(sec, a) < getRankProximity(sec, b);
- });
- if (i == e)
+ if (b == e)
return e;
+ int proximity = getRankProximity(sec, *b);
+ auto i = b;
+ for (auto j = b; ++j != e;) {
+ int p = getRankProximity(sec, *j);
+ if (p > proximity) {
+ proximity = p;
+ i = j;
+ }
+ }
if (!isa<OutputDesc>(*i))
return e;
auto foundSec = &cast<OutputDesc>(*i)->osec;
// Consider all existing sections with the same proximity.
- int proximity = getRankProximity(sec, *i);
unsigned sortRank = sec->sortRank;
if (script->hasPhdrsCommands() || !script->memoryRegions.empty())
// Prevent the orphan section to be placed before the found section. If
More information about the llvm-commits
mailing list