mirror of
https://github.com/RPCS3/llvm.git
synced 2025-04-03 13:51:39 +00:00
Revert "Query the StringMap only once when creating MDString (NFC)"
This reverts commit r261030 and r261036. (The revision was marked "approved" on phabricator, but some concerns were raised on the mailing list. Thanks D. Blaikie for notifying me.) From: Mehdi Amini <mehdi.amini@apple.com> git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@261055 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
5ce6e32359
commit
1df6c24ac6
@ -592,11 +592,9 @@ class MDString : public Metadata {
|
||||
|
||||
StringMapEntry<MDString> *Entry;
|
||||
MDString() : Metadata(MDStringKind, Uniqued), Entry(nullptr) {}
|
||||
MDString(MDString &&) : Metadata(MDStringKind, Uniqued) {}
|
||||
|
||||
public:
|
||||
// This is a "default" move ctor, MSVC does not support "= default" here
|
||||
MDString(MDString &&R)
|
||||
: Metadata(MDStringKind, Uniqued), Entry(std::move(R.Entry)) {}
|
||||
static MDString *get(LLVMContext &Context, StringRef Str);
|
||||
static MDString *get(LLVMContext &Context, const char *Str) {
|
||||
return get(Context, Str ? StringRef(Str) : StringRef());
|
||||
|
@ -397,12 +397,17 @@ void ValueAsMetadata::handleRAUW(Value *From, Value *To) {
|
||||
|
||||
MDString *MDString::get(LLVMContext &Context, StringRef Str) {
|
||||
auto &Store = Context.pImpl->MDStringCache;
|
||||
auto I = Store.insert(std::make_pair(Str, MDString()));
|
||||
auto &MapEntry = I.first->getValue();
|
||||
if (!I.second)
|
||||
return &MapEntry;
|
||||
MapEntry.Entry = &*I.first;
|
||||
return &MapEntry;
|
||||
auto I = Store.find(Str);
|
||||
if (I != Store.end())
|
||||
return &I->second;
|
||||
|
||||
auto *Entry =
|
||||
StringMapEntry<MDString>::Create(Str, Store.getAllocator(), MDString());
|
||||
bool WasInserted = Store.insert(Entry);
|
||||
(void)WasInserted;
|
||||
assert(WasInserted && "Expected entry to be inserted");
|
||||
Entry->second.Entry = Entry;
|
||||
return &Entry->second;
|
||||
}
|
||||
|
||||
StringRef MDString::getString() const {
|
||||
|
Loading…
x
Reference in New Issue
Block a user