[lld] r330879 - Remove unused features from StringRefZ and move it to Symbols.h.
Rui Ueyama via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 25 15:34:21 PDT 2018
Author: ruiu
Date: Wed Apr 25 15:34:21 2018
New Revision: 330879
URL: http://llvm.org/viewvc/llvm-project?rev=330879&view=rev
Log:
Remove unused features from StringRefZ and move it to Symbols.h.
Differential Revision: https://reviews.llvm.org/D46087
Modified:
lld/trunk/ELF/Symbols.h
lld/trunk/include/lld/Common/Strings.h
Modified: lld/trunk/ELF/Symbols.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Symbols.h?rev=330879&r1=330878&r2=330879&view=diff
==============================================================================
--- lld/trunk/ELF/Symbols.h (original)
+++ lld/trunk/ELF/Symbols.h Wed Apr 25 15:34:21 2018
@@ -32,6 +32,20 @@ template <class ELFT> class ObjFile;
class OutputSection;
template <class ELFT> class SharedFile;
+// This is a StringRef-like container that doesn't run strlen().
+//
+// ELF string tables contain a lot of null-terminated strings. Most of them
+// are not necessary for the linker because they are names of local symbols,
+// and the linker doesn't use local symbol names for name resolution. So, we
+// use this class to represents strings read from string tables.
+struct StringRefZ {
+ StringRefZ(const char *S) : Data(S), Size(-1) {}
+ StringRefZ(StringRef S) : Data(S.data()), Size(S.size()) {}
+
+ const char *Data;
+ const uint32_t Size;
+};
+
// The base class for real symbol classes.
class Symbol {
public:
@@ -49,7 +63,7 @@ public:
InputFile *File;
protected:
- const char *NameStart;
+ const char *NameData;
mutable uint32_t NameSize;
public:
@@ -117,9 +131,10 @@ public:
StringRef getName() const {
if (NameSize == (uint32_t)-1)
- NameSize = strlen(NameStart);
- return StringRef(NameStart, NameSize);
+ NameSize = strlen(NameData);
+ return {NameData, NameSize};
}
+
void parseSymbolVersion();
bool isInGot() const { return GotIndex != -1U; }
@@ -138,11 +153,10 @@ public:
protected:
Symbol(Kind K, InputFile *File, StringRefZ Name, uint8_t Binding,
uint8_t StOther, uint8_t Type)
- : File(File), NameStart(Name.data()), NameSize(Name.rawSize()),
- Binding(Binding), Type(Type), StOther(StOther), SymbolKind(K),
- NeedsPltAddr(false), IsInGlobalMipsGot(false), Is32BitMipsGot(false),
- IsInIplt(false), IsInIgot(false), IsPreemptible(false),
- Used(!Config->GcSections) {}
+ : File(File), NameData(Name.Data), NameSize(Name.Size), Binding(Binding),
+ Type(Type), StOther(StOther), SymbolKind(K), NeedsPltAddr(false),
+ IsInGlobalMipsGot(false), Is32BitMipsGot(false), IsInIplt(false),
+ IsInIgot(false), IsPreemptible(false), Used(!Config->GcSections) {}
public:
// True the symbol should point to its PLT entry.
Modified: lld/trunk/include/lld/Common/Strings.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Common/Strings.h?rev=330879&r1=330878&r2=330879&view=diff
==============================================================================
--- lld/trunk/include/lld/Common/Strings.h (original)
+++ lld/trunk/include/lld/Common/Strings.h Wed Apr 25 15:34:21 2018
@@ -26,39 +26,6 @@ llvm::Optional<std::string> demangleMSVC
std::vector<uint8_t> parseHex(llvm::StringRef S);
bool isValidCIdentifier(llvm::StringRef S);
-// This is a lazy version of StringRef. String size is computed lazily
-// when it is needed. It is more efficient than StringRef to instantiate
-// if you have a string whose size is unknown.
-//
-// COFF and ELF string tables contain a lot of null-terminated strings.
-// Most of them are not necessary for the linker because they are names
-// of local symbols and the linker doesn't use local symbol names for
-// name resolution. So, we use this class to represents strings read
-// from string tables.
-class StringRefZ {
-public:
- StringRefZ() : Start(nullptr), Size(0) {}
- StringRefZ(const char *S, size_t Size) : Start(S), Size(Size) {}
-
- /*implicit*/ StringRefZ(const char *S) : Start(S), Size(-1) {}
-
- /*implicit*/ StringRefZ(llvm::StringRef S)
- : Start(S.data()), Size(S.size()) {}
-
- const char *data() const { return Start; }
- size_t rawSize() const { return Size; };
-
- operator llvm::StringRef() const {
- if (Size == (size_t)-1)
- Size = strlen(Start);
- return {Start, Size};
- }
-
-private:
- const char *Start;
- mutable size_t Size;
-};
-
// This class represents multiple glob patterns.
class StringMatcher {
public:
More information about the llvm-commits
mailing list