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 {
|
namespace coff {
|
||||||
|
|
||||||
StringRef Symbol::getName() {
|
void Symbol::computeName() {
|
||||||
// COFF symbol names are read lazily for a performance reason.
|
assert(nameData == nullptr &&
|
||||||
// Non-external symbol names are never used by the linker except for logging
|
"should only compute the name once for DefinedCOFF symbols");
|
||||||
// or debugging. Their internal references are resolved not by name but by
|
auto *d = cast<DefinedCOFF>(this);
|
||||||
// symbol index. And because they are not external, no one can refer them by
|
StringRef nameStr;
|
||||||
// name. Object files contain lots of non-external symbols, and creating
|
cast<ObjFile>(d->file)->getCOFFObj()->getSymbolName(d->sym, nameStr);
|
||||||
// StringRefs for them (which involves lots of strlen() on the string table)
|
nameData = nameStr.data();
|
||||||
// is a waste of time.
|
nameSize = nameStr.size();
|
||||||
if (nameData == nullptr) {
|
assert(nameSize == nameStr.size() && "name length truncated");
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
InputFile *Symbol::getFile() {
|
InputFile *Symbol::getFile() {
|
||||||
|
|
|
@ -69,7 +69,18 @@ public:
|
||||||
Kind kind() const { return static_cast<Kind>(symbolKind); }
|
Kind kind() const { return static_cast<Kind>(symbolKind); }
|
||||||
|
|
||||||
// Returns the symbol name.
|
// 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);
|
void replaceKeepingName(Symbol *other, size_t size);
|
||||||
|
|
||||||
|
@ -84,6 +95,9 @@ public:
|
||||||
return symbolKind == LazyArchiveKind || symbolKind == LazyObjectKind;
|
return symbolKind == LazyArchiveKind || symbolKind == LazyObjectKind;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
void computeName();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
friend SymbolTable;
|
friend SymbolTable;
|
||||||
explicit Symbol(Kind k, StringRef n = "")
|
explicit Symbol(Kind k, StringRef n = "")
|
||||||
|
|
Loading…
Reference in New Issue