[lld] 5816f18 - [ELF] Slightly speed up getOutputSectionName. NFC
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Tue Dec 14 23:43:04 PST 2021
Author: Fangrui Song
Date: 2021-12-14T23:43:00-08:00
New Revision: 5816f1855c1eba836d3c3737fa8a27a9089e7fc3
URL: https://github.com/llvm/llvm-project/commit/5816f1855c1eba836d3c3737fa8a27a9089e7fc3
DIFF: https://github.com/llvm/llvm-project/commit/5816f1855c1eba836d3c3737fa8a27a9089e7fc3.diff
LOG: [ELF] Slightly speed up getOutputSectionName. NFC
Added:
Modified:
lld/ELF/LinkerScript.cpp
Removed:
################################################################################
diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp
index cf4da7ab54c9..3a7228453f18 100644
--- a/lld/ELF/LinkerScript.cpp
+++ b/lld/ELF/LinkerScript.cpp
@@ -50,7 +50,7 @@ using namespace lld::elf;
LinkerScript *elf::script;
static bool isSectionPrefix(StringRef prefix, StringRef name) {
- return name.startswith(prefix) || name == prefix.drop_back();
+ return name.consume_front(prefix) && (name.empty() || name[0] == '.');
}
static StringRef getOutputSectionName(const InputSectionBase *s) {
@@ -94,18 +94,18 @@ static StringRef getOutputSectionName(const InputSectionBase *s) {
// cold parts in .text.split instead of .text.unlikely mitigates against poor
// profile inaccuracy. Techniques such as hugepage remapping can make
// conservative decisions at the section granularity.
- if (config->zKeepTextSectionPrefix)
- for (StringRef v : {".text.hot.", ".text.unknown.", ".text.unlikely.",
- ".text.startup.", ".text.exit.", ".text.split."})
+ if (config->zKeepTextSectionPrefix && s->name.startswith(".text."))
+ for (StringRef v : {".text.hot", ".text.unknown", ".text.unlikely",
+ ".text.startup", ".text.exit", ".text.split"})
if (isSectionPrefix(v, s->name))
- return v.drop_back();
+ return v;
for (StringRef v :
- {".text.", ".rodata.", ".data.rel.ro.", ".data.", ".bss.rel.ro.",
- ".bss.", ".init_array.", ".fini_array.", ".ctors.", ".dtors.", ".tbss.",
- ".gcc_except_table.", ".tdata.", ".ARM.exidx.", ".ARM.extab."})
+ {".text", ".rodata", ".data.rel.ro", ".data", ".bss.rel.ro", ".bss",
+ ".init_array", ".fini_array", ".ctors", ".dtors", ".tbss",
+ ".gcc_except_table", ".tdata", ".ARM.exidx", ".ARM.extab"})
if (isSectionPrefix(v, s->name))
- return v.drop_back();
+ return v;
return s->name;
}
More information about the llvm-commits
mailing list