Cache the result of findSection.
This avoids calling it multiple times. In particular, we don't have to
call in in assignAddresses any more.
llvm-svn: 299709
diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp
index 9e39a5de..c7a8a05 100644
--- a/lld/ELF/LinkerScript.cpp
+++ b/lld/ELF/LinkerScript.cpp
@@ -567,7 +567,7 @@
// This function assigns offsets to input sections and an output section
// for a single sections command (e.g. ".text { *(.text); }").
void LinkerScript::assignOffsets(OutputSectionCommand *Cmd) {
- OutputSection *Sec = findSection(Cmd->Name, *OutputSections);
+ OutputSection *Sec = Cmd->Sec;
if (!Sec)
return;
@@ -614,7 +614,7 @@
auto Pos = std::remove_if(
Opt.Commands.begin(), Opt.Commands.end(), [&](BaseCommand *Base) {
if (auto *Cmd = dyn_cast<OutputSectionCommand>(Base))
- return !findSection(Cmd->Name, *OutputSections);
+ return !Cmd->Sec;
return false;
});
Opt.Commands.erase(Pos, Opt.Commands.end());
@@ -639,6 +639,7 @@
if (!Cmd)
continue;
if (OutputSection *Sec = findSection(Cmd->Name, *OutputSections)) {
+ Cmd->Sec = Sec;
Flags = Sec->Flags;
Type = Sec->Type;
continue;
@@ -649,6 +650,7 @@
auto *OutSec = make<OutputSection>(Cmd->Name, Type, Flags);
OutputSections->push_back(OutSec);
+ Cmd->Sec = OutSec;
}
}
@@ -764,7 +766,9 @@
return Cmd && Cmd->Name == Name;
});
if (Pos == E) {
- Opt.Commands.insert(CmdIter, make<OutputSectionCommand>(Name));
+ auto *Cmd = make<OutputSectionCommand>(Name);
+ Cmd->Sec = Sec;
+ Opt.Commands.insert(CmdIter, Cmd);
++CmdIndex;
continue;
}