[lld] 9b7f614 - [COFF] Paritally inline Symbol::getName, NFC
Reid Kleckner via llvm-commits
llvm-commits at lists.llvm.org
Sun May 3 08:20:04 PDT 2020
Author: Reid Kleckner
Date: 2020-05-03T07:58:05-07:00
New Revision: 9b7f6146bd4734f4ded2c3e572261961a43d3ef2
URL: https://github.com/llvm/llvm-project/commit/9b7f6146bd4734f4ded2c3e572261961a43d3ef2
DIFF: https://github.com/llvm/llvm-project/commit/9b7f6146bd4734f4ded2c3e572261961a43d3ef2.diff
LOG: [COFF] Paritally inline Symbol::getName, NFC
Added:
Modified:
lld/COFF/Symbols.cpp
lld/COFF/Symbols.h
Removed:
################################################################################
diff --git a/lld/COFF/Symbols.cpp b/lld/COFF/Symbols.cpp
index 290a29d8af7d..9cbd245244e8 100644
--- a/lld/COFF/Symbols.cpp
+++ b/lld/COFF/Symbols.cpp
@@ -52,23 +52,15 @@ std::string toCOFFString(const Archive::Symbol &b) {
namespace coff {
-StringRef Symbol::getName() {
- // COFF symbol names are read lazily for a performance reason.
- // Non-external symbol names are never used by the linker except for logging
- // or debugging. Their internal references are resolved not by name but by
- // symbol index. And because they are not external, no one can refer them by
- // name. Object files contain lots of non-external symbols, and creating
- // StringRefs for them (which involves lots of strlen() on the string table)
- // is a waste of time.
- if (nameData == nullptr) {
- auto *d = cast<DefinedCOFF>(this);
- StringRef nameStr;
- cast<ObjFile>(d->file)->getCOFFObj()->getSymbolName(d->sym, nameStr);
- nameData = nameStr.data();
- nameSize = nameStr.size();
- assert(nameSize == nameStr.size() && "name length truncated");
- }
- return StringRef(nameData, nameSize);
+void Symbol::computeName() {
+ assert(nameData == nullptr &&
+ "should only compute the name once for DefinedCOFF symbols");
+ auto *d = cast<DefinedCOFF>(this);
+ StringRef nameStr;
+ cast<ObjFile>(d->file)->getCOFFObj()->getSymbolName(d->sym, nameStr);
+ nameData = nameStr.data();
+ nameSize = nameStr.size();
+ assert(nameSize == nameStr.size() && "name length truncated");
}
InputFile *Symbol::getFile() {
diff --git a/lld/COFF/Symbols.h b/lld/COFF/Symbols.h
index a8e70320b995..1da4df366966 100644
--- a/lld/COFF/Symbols.h
+++ b/lld/COFF/Symbols.h
@@ -69,7 +69,18 @@ class Symbol {
Kind kind() const { return static_cast<Kind>(symbolKind); }
// Returns the symbol name.
- StringRef getName();
+ StringRef getName() {
+ // COFF symbol names are read lazily for a performance reason.
+ // Non-external symbol names are never used by the linker except for logging
+ // or debugging. Their internal references are resolved not by name but by
+ // symbol index. And because they are not external, no one can refer them by
+ // name. Object files contain lots of non-external symbols, and creating
+ // StringRefs for them (which involves lots of strlen() on the string table)
+ // is a waste of time.
+ if (nameData == nullptr)
+ computeName();
+ return StringRef(nameData, nameSize);
+ }
void replaceKeepingName(Symbol *other, size_t size);
@@ -84,6 +95,9 @@ class Symbol {
return symbolKind == LazyArchiveKind || symbolKind == LazyObjectKind;
}
+private:
+ void computeName();
+
protected:
friend SymbolTable;
explicit Symbol(Kind k, StringRef n = "")
More information about the llvm-commits
mailing list