[llvm] 7baad0c - [WebAssembly][MC] Use StringRef over std::string pointer
Sam Clegg via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 8 18:30:08 PDT 2020
Author: Sam Clegg
Date: 2020-04-08T18:28:08-07:00
New Revision: 7baad0c53c56bb18a54c16e20b046246e43ce917
URL: https://github.com/llvm/llvm-project/commit/7baad0c53c56bb18a54c16e20b046246e43ce917
DIFF: https://github.com/llvm/llvm-project/commit/7baad0c53c56bb18a54c16e20b046246e43ce917.diff
LOG: [WebAssembly][MC] Use StringRef over std::string pointer
This is followup based on feedback on 5be42f36f56.
See: https://reviews.llvm.org/D77627.
Differential Revision: https://reviews.llvm.org/D77674
Added:
Modified:
llvm/include/llvm/MC/MCSymbolWasm.h
llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.h
Removed:
################################################################################
diff --git a/llvm/include/llvm/MC/MCSymbolWasm.h b/llvm/include/llvm/MC/MCSymbolWasm.h
index 9c96e7d86c86..da9525922fa2 100644
--- a/llvm/include/llvm/MC/MCSymbolWasm.h
+++ b/llvm/include/llvm/MC/MCSymbolWasm.h
@@ -19,15 +19,13 @@ class MCSymbolWasm : public MCSymbol {
bool IsHidden = false;
bool IsComdat = false;
mutable bool IsUsedInGOT = false;
+ Optional<StringRef> ImportModule;
+ Optional<StringRef> ImportName;
+ Optional<StringRef> ExportName;
+ wasm::WasmSignature *Signature = nullptr;
Optional<wasm::WasmGlobalType> GlobalType;
Optional<wasm::WasmEventType> EventType;
- // Non-owning pointers since MCSymbol must be trivially destructible.
- std::string *ImportModule = nullptr;
- std::string *ImportName = nullptr;
- std::string *ExportName = nullptr;
- wasm::WasmSignature *Signature = nullptr;
-
/// An expression describing how to calculate the size of a symbol. If a
/// symbol has no size this field will be NULL.
const MCExpr *SymbolSize = nullptr;
@@ -71,32 +69,29 @@ class MCSymbolWasm : public MCSymbol {
bool isComdat() const { return IsComdat; }
void setComdat(bool isComdat) { IsComdat = isComdat; }
- bool hasImportModule() const { return ImportModule != nullptr; }
+ bool hasImportModule() const { return ImportModule.hasValue(); }
StringRef getImportModule() const {
- if (ImportModule)
- return StringRef(*ImportModule);
+ if (ImportModule.hasValue())
+ return ImportModule.getValue();
// Use a default module name of "env" for now, for compatibility with
// existing tools.
// TODO(sbc): Find a way to specify a default value in the object format
// without picking a hardcoded value like this.
return "env";
}
- void setImportModule(std::string *Name) { ImportModule = Name; }
+ void setImportModule(StringRef Name) { ImportModule = Name; }
- bool hasImportName() const { return ImportName != nullptr; }
+ bool hasImportName() const { return ImportName.hasValue(); }
StringRef getImportName() const {
- if (ImportName)
- return StringRef(*ImportName);
+ if (ImportName.hasValue())
+ return ImportName.getValue();
return getName();
}
- void setImportName(std::string *Name) { ImportName = Name; }
+ void setImportName(StringRef Name) { ImportName = Name; }
- bool hasExportName() const { return ExportName != nullptr; }
- StringRef getExportName() const {
- assert(ExportName);
- return StringRef(*ExportName);
- }
- void setExportName(std::string *Name) { ExportName = Name; }
+ bool hasExportName() const { return ExportName.hasValue(); }
+ StringRef getExportName() const { return ExportName.getValue(); }
+ void setExportName(StringRef Name) { ExportName = Name; }
void setUsedInGOT() const { IsUsedInGOT = true; }
bool isUsedInGOT() const { return IsUsedInGOT; }
diff --git a/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp b/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
index 68f0cbde8224..a0cef92feff6 100644
--- a/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
+++ b/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
@@ -233,10 +233,10 @@ class WebAssemblyAsmParser final : public MCTargetAsmParser {
Signatures.push_back(std::move(Sig));
}
- std::string *storeName(StringRef Name) {
+ StringRef storeName(StringRef Name) {
std::unique_ptr<std::string> N = std::make_unique<std::string>(Name);
Names.push_back(std::move(N));
- return Names.back().get();
+ return *Names.back();
}
std::pair<StringRef, StringRef> nestingString(NestingType NT) {
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.h b/llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.h
index 5863f556ca33..03bd5e5e97df 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.h
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.h
@@ -28,10 +28,10 @@ class LLVM_LIBRARY_VISIBILITY WebAssemblyAsmPrinter final : public AsmPrinter {
std::vector<std::unique_ptr<wasm::WasmSignature>> Signatures;
std::vector<std::unique_ptr<std::string>> Names;
- std::string *storeName(StringRef Name) {
+ StringRef storeName(StringRef Name) {
std::unique_ptr<std::string> N = std::make_unique<std::string>(Name);
Names.push_back(std::move(N));
- return Names.back().get();
+ return *Names.back();
}
public:
More information about the llvm-commits
mailing list