Use a std::unordered_map for looking up sections by name (#1357)

This commit is contained in:
Sylvie
2024-03-13 19:45:52 -04:00
committed by GitHub
parent 8ec0d01fc4
commit eb99fc8681
3 changed files with 13 additions and 14 deletions

View File

@@ -83,10 +83,8 @@ static uint32_t getSectIDIfAny(Section *sect) {
if (!sect)
return (uint32_t)-1;
for (auto it = sectionList.begin(); it != sectionList.end(); it++) {
if (&*it == sect)
return it - sectionList.begin();
}
if (auto search = sectionMap.find(sect->name); search != sectionMap.end())
return (uint32_t)(sectionMap.size() - search->second - 1);
fatalerror("Unknown section '%s'\n", sect->name.c_str());
}
@@ -373,8 +371,8 @@ void out_WriteObject() {
for (Symbol const *sym : objectSymbols)
writesymbol(*sym, f);
for (Section &sect : sectionList)
writesection(sect, f);
for (auto it = sectionList.rbegin(); it != sectionList.rend(); it++)
writesection(*it, f);
putlong(assertions.size(), f);