Skip to content

Commit 4d4d6eb

Browse files
committed
[ELF] findOrphanPos: avoid redundant getRankProximity call. NFC
1 parent f3444f6 commit 4d4d6eb

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

lld/ELF/Writer.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -936,17 +936,22 @@ findOrphanPos(SmallVectorImpl<SectionCommand *>::iterator b,
936936
}
937937

938938
// Find the first element that has as close a rank as possible.
939-
auto i = std::max_element(b, e, [=](SectionCommand *a, SectionCommand *b) {
940-
return getRankProximity(sec, a) < getRankProximity(sec, b);
941-
});
942-
if (i == e)
939+
if (b == e)
943940
return e;
941+
int proximity = getRankProximity(sec, *b);
942+
auto i = b;
943+
for (auto j = b; ++j != e;) {
944+
int p = getRankProximity(sec, *j);
945+
if (p > proximity) {
946+
proximity = p;
947+
i = j;
948+
}
949+
}
944950
if (!isa<OutputDesc>(*i))
945951
return e;
946952
auto foundSec = &cast<OutputDesc>(*i)->osec;
947953

948954
// Consider all existing sections with the same proximity.
949-
int proximity = getRankProximity(sec, *i);
950955
unsigned sortRank = sec->sortRank;
951956
if (script->hasPhdrsCommands() || !script->memoryRegions.empty())
952957
// Prevent the orphan section to be placed before the found section. If

0 commit comments

Comments
 (0)