forked from OSchip/llvm-project
[COFF] Paritally inline Symbol::getName, NFC
This commit is contained in:
parent
682f0b366b
commit
9b7f6146bd
|
@ -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() {
|
||||
|
|
|
@ -69,7 +69,18 @@ public:
|
|||
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 @@ public:
|
|||
return symbolKind == LazyArchiveKind || symbolKind == LazyObjectKind;
|
||||
}
|
||||
|
||||
private:
|
||||
void computeName();
|
||||
|
||||
protected:
|
||||
friend SymbolTable;
|
||||
explicit Symbol(Kind k, StringRef n = "")
|
||||
|
|
Loading…
Reference in New Issue