diff options
author | David Blaikie <dblaikie@gmail.com> | 2014-11-19 03:06:06 +0000 |
---|---|---|
committer | David Blaikie <dblaikie@gmail.com> | 2014-11-19 03:06:06 +0000 |
commit | 8ee697fb1b40b4b5c3b34176ae60add0a815c44d (patch) | |
tree | 079c5e6c267ab1e1f04f9d66c0b4b921d0cb3e22 | |
parent | 14b0eac48e69f7bea5815c1614310497fdc49c30 (diff) |
Standardize on StringMap::insert, removing uses of StringMap::GetOrCreateValue.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@222306 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/clang/Basic/IdentifierTable.h | 47 | ||||
-rw-r--r-- | include/clang/Lex/HeaderSearch.h | 2 | ||||
-rw-r--r-- | lib/ARCMigrate/ObjCMT.cpp | 10 | ||||
-rw-r--r-- | lib/ARCMigrate/TransformActions.cpp | 3 | ||||
-rw-r--r-- | lib/Basic/FileManager.cpp | 69 | ||||
-rw-r--r-- | lib/Basic/SourceManager.cpp | 16 | ||||
-rw-r--r-- | lib/CodeGen/CGOpenMPRuntime.cpp | 18 | ||||
-rw-r--r-- | lib/CodeGen/CodeGenModule.cpp | 30 | ||||
-rw-r--r-- | lib/Frontend/CacheTokens.cpp | 10 | ||||
-rw-r--r-- | lib/Lex/HeaderSearch.cpp | 28 | ||||
-rw-r--r-- | lib/Lex/Pragma.cpp | 4 | ||||
-rw-r--r-- | lib/StaticAnalyzer/Core/AnalyzerOptions.cpp | 17 | ||||
-rw-r--r-- | lib/StaticAnalyzer/Core/BugReporter.cpp | 8 | ||||
-rw-r--r-- | tools/diagtool/DiagTool.cpp | 2 | ||||
-rw-r--r-- | tools/diagtool/ListWarnings.cpp | 4 | ||||
-rw-r--r-- | unittests/Tooling/RefactoringTest.cpp | 3 | ||||
-rw-r--r-- | unittests/Tooling/RewriterTestContext.h | 3 |
17 files changed, 128 insertions, 146 deletions
diff --git a/include/clang/Basic/IdentifierTable.h b/include/clang/Basic/IdentifierTable.h index a6a174a41c..50f9b88998 100644 --- a/include/clang/Basic/IdentifierTable.h +++ b/include/clang/Basic/IdentifierTable.h @@ -444,26 +444,21 @@ public: /// \brief Return the identifier token info for the specified named /// identifier. IdentifierInfo &get(StringRef Name) { - llvm::StringMapEntry<IdentifierInfo*> &Entry = - HashTable.GetOrCreateValue(Name); + auto &Entry = *HashTable.insert(std::make_pair(Name, nullptr)).first; - IdentifierInfo *II = Entry.getValue(); + IdentifierInfo *&II = Entry.second; if (II) return *II; // No entry; if we have an external lookup, look there first. if (ExternalLookup) { II = ExternalLookup->get(Name); - if (II) { - // Cache in the StringMap for subsequent lookups. - Entry.setValue(II); + if (II) return *II; - } } // Lookups failed, make a new IdentifierInfo. void *Mem = getAllocator().Allocate<IdentifierInfo>(); II = new (Mem) IdentifierInfo(); - Entry.setValue(II); // Make sure getName() knows how to find the IdentifierInfo // contents. @@ -486,25 +481,23 @@ public: /// introduce or modify an identifier. If they called get(), they would /// likely end up in a recursion. IdentifierInfo &getOwn(StringRef Name) { - llvm::StringMapEntry<IdentifierInfo*> &Entry = - HashTable.GetOrCreateValue(Name); - - IdentifierInfo *II = Entry.getValue(); - if (!II) { - - // Lookups failed, make a new IdentifierInfo. - void *Mem = getAllocator().Allocate<IdentifierInfo>(); - II = new (Mem) IdentifierInfo(); - Entry.setValue(II); - - // Make sure getName() knows how to find the IdentifierInfo - // contents. - II->Entry = &Entry; - - // If this is the 'import' contextual keyword, mark it as such. - if (Name.equals("import")) - II->setModulesImport(true); - } + auto &Entry = *HashTable.insert(std::make_pair(Name, nullptr)).first; + + IdentifierInfo *&II = Entry.second; + if (II) + return *II; + + // Lookups failed, make a new IdentifierInfo. + void *Mem = getAllocator().Allocate<IdentifierInfo>(); + II = new (Mem) IdentifierInfo(); + + // Make sure getName() knows how to find the IdentifierInfo + // contents. + II->Entry = &Entry; + + // If this is the 'import' contextual keyword, mark it as such. + if (Name.equals("import")) + II->setModulesImport(true); return *II; } diff --git a/include/clang/Lex/HeaderSearch.h b/include/clang/Lex/HeaderSearch.h index 086d3481b8..47e3313320 100644 --- a/include/clang/Lex/HeaderSearch.h +++ b/include/clang/Lex/HeaderSearch.h @@ -411,7 +411,7 @@ public: /// \brief Look up the specified framework name in our framework cache. /// \returns The DirectoryEntry it is in if we know, null otherwise. FrameworkCacheEntry &LookupFrameworkCache(StringRef FWName) { - return FrameworkMap.GetOrCreateValue(FWName).getValue(); + return FrameworkMap[FWName]; } /// \brief Mark the specified file as a target of of a \#include, diff --git a/lib/ARCMigrate/ObjCMT.cpp b/lib/ARCMigrate/ObjCMT.cpp index 01d37c378c..4ad961c31f 100644 --- a/lib/ARCMigrate/ObjCMT.cpp +++ b/lib/ARCMigrate/ObjCMT.cpp @@ -29,6 +29,7 @@ #include "clang/Rewrite/Core/Rewriter.h" #include "clang/StaticAnalyzer/Checkers/ObjCRetainCount.h" #include "llvm/ADT/SmallString.h" +#include "llvm/ADT/StringSet.h" #include "llvm/Support/Path.h" #include "llvm/Support/SourceMgr.h" #include "llvm/Support/YAMLParser.h" @@ -100,7 +101,7 @@ public: bool FoundationIncluded; llvm::SmallPtrSet<ObjCProtocolDecl *, 32> ObjCProtocolDecls; llvm::SmallVector<const Decl *, 8> CFFunctionIBCandidates; - llvm::StringMap<char> WhiteListFilenames; + llvm::StringSet<> WhiteListFilenames; ObjCMigrateASTConsumer(StringRef migrateDir, unsigned astMigrateActions, @@ -117,10 +118,9 @@ public: IsOutputFile(isOutputFile), FoundationIncluded(false){ - for (ArrayRef<std::string>::iterator - I = WhiteList.begin(), E = WhiteList.end(); I != E; ++I) { - WhiteListFilenames.GetOrCreateValue(*I); - } + // FIXME: StringSet should have insert(iter, iter) to use here. + for (const std::string &Val : WhiteList) + WhiteListFilenames.insert(Val); } protected: diff --git a/lib/ARCMigrate/TransformActions.cpp b/lib/ARCMigrate/TransformActions.cpp index 6d178bea09..9fb2f1d3ee 100644 --- a/lib/ARCMigrate/TransformActions.cpp +++ b/lib/ARCMigrate/TransformActions.cpp @@ -581,8 +581,7 @@ void TransformActionsImpl::applyRewrites( /// "alive". Since the vast majority of text will be the same, we also unique /// the strings using a StringMap. StringRef TransformActionsImpl::getUniqueText(StringRef text) { - llvm::StringMapEntry<bool> &entry = UniqueText.GetOrCreateValue(text); - return entry.getKey(); + return UniqueText.insert(std::make_pair(text, false)).first->first(); } /// \brief Computes the source location just past the end of the token at diff --git a/lib/Basic/FileManager.cpp b/lib/Basic/FileManager.cpp index 91681edcc5..af6022fdc9 100644 --- a/lib/Basic/FileManager.cpp +++ b/lib/Basic/FileManager.cpp @@ -129,20 +129,20 @@ void FileManager::addAncestorsAsVirtualDirs(StringRef Path) { if (DirName.empty()) return; - llvm::StringMapEntry<DirectoryEntry *> &NamedDirEnt = - SeenDirEntries.GetOrCreateValue(DirName); + auto &NamedDirEnt = + *SeenDirEntries.insert(std::make_pair(DirName, nullptr)).first; // When caching a virtual directory, we always cache its ancestors // at the same time. Therefore, if DirName is already in the cache, // we don't need to recurse as its ancestors must also already be in // the cache. - if (NamedDirEnt.getValue()) + if (NamedDirEnt.second) return; // Add the virtual directory to the cache. DirectoryEntry *UDE = new DirectoryEntry; - UDE->Name = NamedDirEnt.getKeyData(); - NamedDirEnt.setValue(UDE); + UDE->Name = NamedDirEnt.first().data(); + NamedDirEnt.second = UDE; VirtualDirectoryEntries.push_back(UDE); // Recursively add the other ancestors. @@ -170,23 +170,23 @@ const DirectoryEntry *FileManager::getDirectory(StringRef DirName, #endif ++NumDirLookups; - llvm::StringMapEntry<DirectoryEntry *> &NamedDirEnt = - SeenDirEntries.GetOrCreateValue(DirName); + auto &NamedDirEnt = + *SeenDirEntries.insert(std::make_pair(DirName, nullptr)).first; // See if there was already an entry in the map. Note that the map // contains both virtual and real directories. - if (NamedDirEnt.getValue()) - return NamedDirEnt.getValue() == NON_EXISTENT_DIR ? nullptr - : NamedDirEnt.getValue(); + if (NamedDirEnt.second) + return NamedDirEnt.second == NON_EXISTENT_DIR ? nullptr + : NamedDirEnt.second; ++NumDirCacheMisses; // By default, initialize it to invalid. - NamedDirEnt.setValue(NON_EXISTENT_DIR); + NamedDirEnt.second = NON_EXISTENT_DIR; // Get the null-terminated directory name as stored as the key of the // SeenDirEntries map. - const char *InterndDirName = NamedDirEnt.getKeyData(); + const char *InterndDirName = NamedDirEnt.first().data(); // Check to see if the directory exists. FileData Data; @@ -203,7 +203,7 @@ const DirectoryEntry *FileManager::getDirectory(StringRef DirName, // Windows). DirectoryEntry &UDE = UniqueRealDirs[Data.UniqueID]; - NamedDirEnt.setValue(&UDE); + NamedDirEnt.second = &UDE; if (!UDE.getName()) { // We don't have this directory yet, add it. We use the string // key from the SeenDirEntries map as the string. @@ -218,22 +218,22 @@ const FileEntry *FileManager::getFile(StringRef Filename, bool openFile, ++NumFileLookups; // See if there is already an entry in the map. - llvm::StringMapEntry<FileEntry *> &NamedFileEnt = - SeenFileEntries.GetOrCreateValue(Filename); + auto &NamedFileEnt = + *SeenFileEntries.insert(std::make_pair(Filename, nullptr)).first; // See if there is already an entry in the map. - if (NamedFileEnt.getValue()) - return NamedFileEnt.getValue() == NON_EXISTENT_FILE - ? nullptr : NamedFileEnt.getValue(); + if (NamedFileEnt.second) + return NamedFileEnt.second == NON_EXISTENT_FILE ? nullptr + : NamedFileEnt.second; ++NumFileCacheMisses; // By default, initialize it to invalid. - NamedFileEnt.setValue(NON_EXISTENT_FILE); + NamedFileEnt.second = NON_EXISTENT_FILE; // Get the null-terminated file name as stored as the key of the // SeenFileEntries map. - const char *InterndFileName = NamedFileEnt.getKeyData(); + const char *InterndFileName = NamedFileEnt.first().data(); // Look up the directory for the file. When looking up something like // sys/foo.h we'll discover all of the search directories that have a 'sys' @@ -269,18 +269,19 @@ const FileEntry *FileManager::getFile(StringRef Filename, bool openFile, // This occurs when one dir is symlinked to another, for example. FileEntry &UFE = UniqueRealFiles[Data.UniqueID]; - NamedFileEnt.setValue(&UFE); + NamedFileEnt.second = &UFE; // If the name returned by getStatValue is different than Filename, re-intern // the name. if (Data.Name != Filename) { - auto &NamedFileEnt = SeenFileEntries.GetOrCreateValue(Data.Name); - if (!NamedFileEnt.getValue()) - NamedFileEnt.setValue(&UFE); + auto &NamedFileEnt = + *SeenFileEntries.insert(std::make_pair(Data.Name, nullptr)).first; + if (!NamedFileEnt.second) + NamedFileEnt.second = &UFE; else - assert(NamedFileEnt.getValue() == &UFE && + assert(NamedFileEnt.second == &UFE && "filename from getStatValue() refers to wrong file"); - InterndFileName = NamedFileEnt.getKeyData(); + InterndFileName = NamedFileEnt.first().data(); } if (UFE.isValid()) { // Already have an entry with this inode, return it. @@ -324,17 +325,17 @@ FileManager::getVirtualFile(StringRef Filename, off_t Size, ++NumFileLookups; // See if there is already an entry in the map. - llvm::StringMapEntry<FileEntry *> &NamedFileEnt = - SeenFileEntries.GetOrCreateValue(Filename); + auto &NamedFileEnt = + *SeenFileEntries.insert(std::make_pair(Filename, nullptr)).first; // See if there is already an entry in the map. - if (NamedFileEnt.getValue() && NamedFileEnt.getValue() != NON_EXISTENT_FILE) - return NamedFileEnt.getValue(); + if (NamedFileEnt.second && NamedFileEnt.second != NON_EXISTENT_FILE) + return NamedFileEnt.second; ++NumFileCacheMisses; // By default, initialize it to invalid. - NamedFileEnt.setValue(NON_EXISTENT_FILE); + NamedFileEnt.second = NON_EXISTENT_FILE; addAncestorsAsVirtualDirs(Filename); FileEntry *UFE = nullptr; @@ -349,13 +350,13 @@ FileManager::getVirtualFile(StringRef Filename, off_t Size, // Check to see if the file exists. If so, drop the virtual file FileData Data; - const char *InterndFileName = NamedFileEnt.getKeyData(); + const char *InterndFileName = NamedFileEnt.first().data(); if (getStatValue(InterndFileName, Data, true, nullptr) == 0) { Data.Size = Size; Data.ModTime = ModificationTime; UFE = &UniqueRealFiles[Data.UniqueID]; - NamedFileEnt.setValue(UFE); + NamedFileEnt.second = UFE; // If we had already opened this file, close it now so we don't // leak the descriptor. We're not going to use the file @@ -375,7 +376,7 @@ FileManager::getVirtualFile(StringRef Filename, off_t Size, if (!UFE) { UFE = new FileEntry(); VirtualFileEntries.push_back(UFE); - NamedFileEnt.setValue(UFE); + NamedFileEnt.second = UFE; } UFE->Name = InterndFileName; diff --git a/lib/Basic/SourceManager.cpp b/lib/Basic/SourceManager.cpp index 6991783056..305dcd4396 100644 --- a/lib/Basic/SourceManager.cpp +++ b/lib/Basic/SourceManager.cpp @@ -177,17 +177,11 @@ llvm::MemoryBuffer *ContentCache::getBuffer(DiagnosticsEngine &Diag, } unsigned LineTableInfo::getLineTableFilenameID(StringRef Name) { - // Look up the filename in the string table, returning the pre-existing value - // if it exists. - llvm::StringMapEntry<unsigned> &Entry = - FilenameIDs.GetOrCreateValue(Name, ~0U); - if (Entry.getValue() != ~0U) - return Entry.getValue(); - - // Otherwise, assign this the next available ID. - Entry.setValue(FilenamesByID.size()); - FilenamesByID.push_back(&Entry); - return FilenamesByID.size()-1; + auto IterBool = + FilenameIDs.insert(std::make_pair(Name, FilenamesByID.size())); + if (IterBool.second) + FilenamesByID.push_back(&*IterBool.first); + return IterBool.first->second; } /// AddLineNote - Add a line note to the line table that indicates that there diff --git a/lib/CodeGen/CGOpenMPRuntime.cpp b/lib/CodeGen/CGOpenMPRuntime.cpp index 8b02bd5c25..bcd9d3363a 100644 --- a/lib/CodeGen/CGOpenMPRuntime.cpp +++ b/lib/CodeGen/CGOpenMPRuntime.cpp @@ -590,19 +590,17 @@ CGOpenMPRuntime::GetOrCreateInternalVariable(llvm::Type *Ty, llvm::raw_svector_ostream Out(Buffer); Out << Name; auto RuntimeName = Out.str(); - auto &Elem = InternalVars.GetOrCreateValue(RuntimeName); - if (Elem.getValue()) { - assert(Elem.getValue()->getType()->getPointerElementType() == Ty && + auto &Elem = *InternalVars.insert(std::make_pair(RuntimeName, nullptr)).first; + if (Elem.second) { + assert(Elem.second->getType()->getPointerElementType() == Ty && "OMP internal variable has different type than requested"); - return &*Elem.getValue(); + return &*Elem.second; } - auto Item = new llvm::GlobalVariable( - CGM.getModule(), Ty, /*IsConstant*/ false, - llvm::GlobalValue::CommonLinkage, - llvm::Constant::getNullValue(Ty), Elem.getKey()); - Elem.setValue(Item); - return Item; + return Elem.second = new llvm::GlobalVariable( + CGM.getModule(), Ty, /*IsConstant*/ false, + llvm::GlobalValue::CommonLinkage, llvm::Constant::getNullValue(Ty), + Elem.first()); } llvm::Value *CGOpenMPRuntime::GetCriticalRegionLock(StringRef CriticalName) { diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp index a68f369457..7462f96e51 100644 --- a/lib/CodeGen/CodeGenModule.cpp +++ b/lib/CodeGen/CodeGenModule.cpp @@ -2470,7 +2470,7 @@ GetConstantCFStringEntry(llvm::StringMap<llvm::Constant*> &Map, // Check for simple case. if (!Literal->containsNonAsciiOrNull()) { StringLength = NumBytes; - return Map.GetOrCreateValue(String); + return *Map.insert(std::make_pair(String, nullptr)).first; } // Otherwise, convert the UTF8 literals into a string of shorts. @@ -2489,9 +2489,10 @@ GetConstantCFStringEntry(llvm::StringMap<llvm::Constant*> &Map, // Add an explicit null. *ToPtr = 0; - return Map. - GetOrCreateValue(StringRef(reinterpret_cast<const char *>(ToBuf.data()), - (StringLength + 1) * 2)); + return *Map.insert(std::make_pair( + StringRef(reinterpret_cast<const char *>(ToBuf.data()), + (StringLength + 1) * 2), + nullptr)).first; } static llvm::StringMapEntry<llvm::Constant*> & @@ -2500,7 +2501,7 @@ GetConstantStringEntry(llvm::StringMap<llvm::Constant*> &Map, unsigned &StringLength) { StringRef String = Literal->getString(); StringLength = String.size(); - return Map.GetOrCreateValue(String); + return *Map.insert(std::make_pair(String, nullptr)).first; } llvm::Constant * @@ -2512,7 +2513,7 @@ CodeGenModule::GetAddrOfConstantCFString(const StringLiteral *Literal) { getDataLayout().isLittleEndian(), isUTF16, StringLength); - if (llvm::Constant *C = Entry.getValue()) + if (auto *C = Entry.second) return C; llvm::Constant *Zero = llvm::Constant::getNullValue(Int32Ty); @@ -2549,13 +2550,12 @@ CodeGenModule::GetAddrOfConstantCFString(const StringLiteral *Literal) { // String pointer. llvm::Constant *C = nullptr; if (isUTF16) { - ArrayRef<uint16_t> Arr = - llvm::makeArrayRef<uint16_t>(reinterpret_cast<uint16_t*>( - const_cast<char *>(Entry.getKey().data())), - Entry.getKey().size() / 2); + ArrayRef<uint16_t> Arr = llvm::makeArrayRef<uint16_t>( + reinterpret_cast<uint16_t *>(const_cast<char *>(Entry.first().data())), + Entry.first().size() / 2); C = llvm::ConstantDataArray::get(VMContext, Arr); } else { - C = llvm::ConstantDataArray::getString(VMContext, Entry.getKey()); + C = llvm::ConstantDataArray::getString(VMContext, Entry.first()); } // Note: -fwritable-strings doesn't make the backing store strings of @@ -2596,7 +2596,7 @@ CodeGenModule::GetAddrOfConstantCFString(const StringLiteral *Literal) { llvm::GlobalVariable::PrivateLinkage, C, "_unnamed_cfstring_"); GV->setSection("__DATA,__cfstring"); - Entry.setValue(GV); + Entry.second = GV; return GV; } @@ -2607,7 +2607,7 @@ CodeGenModule::GetAddrOfConstantString(const StringLiteral *Literal) { llvm::StringMapEntry<llvm::Constant*> &Entry = GetConstantStringEntry(CFConstantStringMap, Literal, StringLength); - if (llvm::Constant *C = Entry.getValue()) + if (auto *C = Entry.second) return C; llvm::Constant *Zero = llvm::Constant::getNullValue(Int32Ty); @@ -2680,7 +2680,7 @@ CodeGenModule::GetAddrOfConstantString(const StringLiteral *Literal) { // String pointer. llvm::Constant *C = - llvm::ConstantDataArray::getString(VMContext, Entry.getKey()); + llvm::ConstantDataArray::getString(VMContext, Entry.first()); llvm::GlobalValue::LinkageTypes Linkage; bool isConstant; @@ -2712,7 +2712,7 @@ CodeGenModule::GetAddrOfConstantString(const StringLiteral *Literal) { GV->setSection(LangOpts.ObjCRuntime.isNonFragile() ? NSStringNonFragileABISection : NSStringSection); - Entry.setValue(GV); + Entry.second = GV; return GV; } diff --git a/lib/Frontend/CacheTokens.cpp b/lib/Frontend/CacheTokens.cpp index 23f22ada7f..d909d526b5 100644 --- a/lib/Frontend/CacheTokens.cpp +++ b/lib/Frontend/CacheTokens.cpp @@ -270,17 +270,17 @@ void PTHWriter::EmitToken(const Token& T) { StringRef s(T.getLiteralData(), T.getLength()); // Get the string entry. - llvm::StringMapEntry<OffsetOpt> *E = &CachedStrs.GetOrCreateValue(s); + auto &E = *CachedStrs.insert(std::make_pair(s, OffsetOpt())).first; // If this is a new string entry, bump the PTH offset. - if (!E->getValue().hasOffset()) { - E->getValue().setOffset(CurStrOffset); - StrEntries.push_back(E); + if (!E.second.hasOffset()) { + E.second.setOffset(CurStrOffset); + StrEntries.push_back(&E); CurStrOffset += s.size() + 1; } // Emit the relative offset into the PTH file for the spelling string. - Emit32(E->getValue().getOffset()); + Emit32(E.second.getOffset()); } // Emit the offset into the original source file of this token so that we diff --git a/lib/Lex/HeaderSearch.cpp b/lib/Lex/HeaderSearch.cpp index e16b537c92..259fbd57bb 100644 --- a/lib/Lex/HeaderSearch.cpp +++ b/lib/Lex/HeaderSearch.cpp @@ -690,8 +690,7 @@ const FileEntry *HeaderSearch::LookupFile( // multiply included, and the "pragma once" optimization prevents them from // being relex/pp'd, but they would still have to search through a // (potentially huge) series of SearchDirs to find it. - LookupFileCacheInfo &CacheLookup = - LookupFileCache.GetOrCreateValue(Filename).getValue(); + LookupFileCacheInfo &CacheLookup = LookupFileCache[Filename]; // If the entry has been previously looked up, the first value will be // non-zero. If the value is equal to i (the start point of our search), then @@ -791,10 +790,8 @@ const FileEntry *HeaderSearch::LookupFile( return MSFE; } - LookupFileCacheInfo &CacheLookup - = LookupFileCache.GetOrCreateValue(Filename).getValue(); - CacheLookup.HitIdx - = LookupFileCache.GetOrCreateValue(ScratchFilename).getValue().HitIdx; + LookupFileCacheInfo &CacheLookup = LookupFileCache[Filename]; + CacheLookup.HitIdx = LookupFileCache[ScratchFilename].HitIdx; // FIXME: SuggestedModule. return FE; } @@ -847,18 +844,19 @@ LookupSubframeworkHeader(StringRef Filename, FrameworkName.append(Filename.begin(), Filename.begin()+SlashPos); FrameworkName += ".framework/"; - llvm::StringMapEntry<FrameworkCacheEntry> &CacheLookup = - FrameworkMap.GetOrCreateValue(Filename.substr(0, SlashPos)); + auto &CacheLookup = + *FrameworkMap.insert(std::make_pair(Filename.substr(0, SlashPos), + FrameworkCacheEntry())).first; // Some other location? - if (CacheLookup.getValue().Directory && - CacheLookup.getKeyLength() == FrameworkName.size() && - memcmp(CacheLookup.getKeyData(), &FrameworkName[0], - CacheLookup.getKeyLength()) != 0) + if (CacheLookup.second.Directory && + CacheLookup.first().size() == FrameworkName.size() && + memcmp(CacheLookup.first().data(), &FrameworkName[0], + CacheLookup.first().size()) != 0) return nullptr; // Cache subframework. - if (!CacheLookup.getValue().Directory) { + if (!CacheLookup.second.Directory) { ++NumSubFrameworkLookups; // If the framework dir doesn't exist, we fail. @@ -867,7 +865,7 @@ LookupSubframeworkHeader(StringRef Filename, // Otherwise, if it does, remember that this is the right direntry for this // framework. - CacheLookup.getValue().Directory = Dir; + CacheLookup.second.Directory = Dir; } const FileEntry *FE = nullptr; @@ -1058,7 +1056,7 @@ size_t HeaderSearch::getTotalMemory() const { } StringRef HeaderSearch::getUniqueFrameworkName(StringRef Framework) { - return FrameworkNames.GetOrCreateValue(Framework).getKey(); + return FrameworkNames.insert(Framework).first->first(); } bool HeaderSearch::hasModuleMap(StringRef FileName, diff --git a/lib/Lex/Pragma.cpp b/lib/Lex/Pragma.cpp index b91030feeb..8ed8328937 100644 --- a/lib/Lex/Pragma.cpp +++ b/lib/Lex/Pragma.cpp @@ -65,9 +65,7 @@ PragmaHandler *PragmaNamespace::FindHandler(StringRef Name, void PragmaNamespace::AddPragma(PragmaHandler *Handler) { assert(!Handlers.lookup(Handler->getName()) && "A handler with this name is already registered in this namespace"); - llvm::StringMapEntry<PragmaHandler *> &Entry = - Handlers.GetOrCreateValue(Handler->getName()); - Entry.setValue(Handler); + Handlers[Handler->getName()] = Handler; } void PragmaNamespace::RemovePragmaHandler(PragmaHandler *Handler) { diff --git a/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp b/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp index 7944c7eb00..4ec3d2750e 100644 --- a/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp +++ b/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp @@ -23,7 +23,8 @@ using namespace llvm; AnalyzerOptions::UserModeKind AnalyzerOptions::getUserMode() { if (UserMode == UMK_NotSet) { - StringRef ModeStr(Config.GetOrCreateValue("mode", "deep").getValue()); + StringRef ModeStr = + Config.insert(std::make_pair("mode", "deep")).first->second; UserMode = llvm::StringSwitch<UserModeKind>(ModeStr) .Case("shallow", UMK_Shallow) .Case("deep", UMK_Deep) @@ -48,7 +49,8 @@ IPAKind AnalyzerOptions::getIPAMode() { assert(DefaultIPA); // Lookup the ipa configuration option, use the default from User Mode. - StringRef ModeStr(Config.GetOrCreateValue("ipa", DefaultIPA).getValue()); + StringRef ModeStr = + Config.insert(std::make_pair("ipa", DefaultIPA)).first->second; IPAKind IPAConfig = llvm::StringSwitch<IPAKind>(ModeStr) .Case("none", IPAK_None) .Case("basic-inlining", IPAK_BasicInlining) @@ -72,9 +74,9 @@ AnalyzerOptions::mayInlineCXXMemberFunction(CXXInlineableMemberKind K) { if (!CXXMemberInliningMode) { static const char *ModeKey = "c++-inlining"; - - StringRef ModeStr(Config.GetOrCreateValue(ModeKey, - "destructors").getValue()); + + StringRef ModeStr = + Config.insert(std::make_pair(ModeKey, "destructors")).first->second; CXXInlineableMemberKind &MutableMode = const_cast<CXXInlineableMemberKind &>(CXXMemberInliningMode); @@ -102,7 +104,8 @@ bool AnalyzerOptions::getBooleanOption(StringRef Name, bool DefaultVal) { // FIXME: We should emit a warning here if the value is something other than // "true", "false", or the empty string (meaning the default value), // but the AnalyzerOptions doesn't have access to a diagnostic engine. - StringRef V(Config.GetOrCreateValue(Name, toString(DefaultVal)).getValue()); + StringRef V = + Config.insert(std::make_pair(Name, toString(DefaultVal))).first->second; return llvm::StringSwitch<bool>(V) .Case("true", true) .Case("false", false) @@ -201,7 +204,7 @@ int AnalyzerOptions::getOptionAsInteger(StringRef Name, int DefaultVal) { llvm::raw_svector_ostream OS(StrBuf); OS << DefaultVal; - StringRef V(Config.GetOrCreateValue(Name, OS.str()).getValue()); + StringRef V = Config.insert(std::make_pair(Name, OS.str())).first->second; int Res = DefaultVal; bool b = V.getAsInteger(10, Res); assert(!b && "analyzer-config option should be numeric"); diff --git a/lib/StaticAnalyzer/Core/BugReporter.cpp b/lib/StaticAnalyzer/Core/BugReporter.cpp index 0b9c95c1df..dff81e383e 100644 --- a/lib/StaticAnalyzer/Core/BugReporter.cpp +++ b/lib/StaticAnalyzer/Core/BugReporter.cpp @@ -3480,13 +3480,9 @@ BugType *BugReporter::getBugTypeForName(CheckName CheckName, StringRef name, SmallString<136> fullDesc; llvm::raw_svector_ostream(fullDesc) << CheckName.getName() << ":" << name << ":" << category; - llvm::StringMapEntry<BugType *> & - entry = StrBugTypes.GetOrCreateValue(fullDesc); - BugType *BT = entry.getValue(); - if (!BT) { + BugType *&BT = StrBugTypes[fullDesc]; + if (!BT) BT = new BugType(CheckName, name, category); - entry.setValue(BT); - } return BT; } diff --git a/tools/diagtool/DiagTool.cpp b/tools/diagtool/DiagTool.cpp index 44bc83e545..0e4d8088c6 100644 --- a/tools/diagtool/DiagTool.cpp +++ b/tools/diagtool/DiagTool.cpp @@ -36,7 +36,7 @@ DiagTool *DiagTools::getTool(llvm::StringRef toolCmd) { } void DiagTools::registerTool(DiagTool *tool) { - getTools(tools)->GetOrCreateValue(tool->getName(), tool); + (*getTools(tools))[tool->getName()] = tool; } void DiagTools::printCommands(llvm::raw_ostream &out) { diff --git a/tools/diagtool/ListWarnings.cpp b/tools/diagtool/ListWarnings.cpp index 16837a1584..5a26fc2282 100644 --- a/tools/diagtool/ListWarnings.cpp +++ b/tools/diagtool/ListWarnings.cpp @@ -73,7 +73,7 @@ int ListWarnings::run(unsigned int argc, char **argv, llvm::raw_ostream &out) { Unflagged.push_back(entry); else { Flagged.push_back(entry); - flagHistogram.GetOrCreateValue(entry.Flag).getValue().push_back(diagID); + flagHistogram[entry.Flag].push_back(diagID); } } @@ -99,7 +99,7 @@ int ListWarnings::run(unsigned int argc, char **argv, llvm::raw_ostream &out) { << llvm::format("%.4g", avgDiagsPerFlag) << '\n'; out << " Number in -Wpedantic (not covered by other -W flags): " - << flagHistogram.GetOrCreateValue("pedantic").getValue().size() + << flagHistogram["pedantic"].size() << '\n'; out << '\n'; diff --git a/unittests/Tooling/RefactoringTest.cpp b/unittests/Tooling/RefactoringTest.cpp index 4935bdd806..a026a94261 100644 --- a/unittests/Tooling/RefactoringTest.cpp +++ b/unittests/Tooling/RefactoringTest.cpp @@ -237,7 +237,8 @@ public: const FileEntry *File = Context.Files.getFile(Path); assert(File != nullptr); - StringRef Found = TemporaryFiles.GetOrCreateValue(Name, Path.str()).second; + StringRef Found = + TemporaryFiles.insert(std::make_pair(Name, Path.str())).first->second; assert(Found == Path); (void)Found; return Context.Sources.createFileID(File, SourceLocation(), SrcMgr::C_User); diff --git a/unittests/Tooling/RewriterTestContext.h b/unittests/Tooling/RewriterTestContext.h index 78ee788a1e..112efac52e 100644 --- a/unittests/Tooling/RewriterTestContext.h +++ b/unittests/Tooling/RewriterTestContext.h @@ -72,7 +72,8 @@ class RewriterTestContext { const FileEntry *File = Files.getFile(Path); assert(File != nullptr); - StringRef Found = TemporaryFiles.GetOrCreateValue(Name, Path.str()).second; + StringRef Found = + TemporaryFiles.insert(std::make_pair(Name, Path.str())).first->second; assert(Found == Path); (void)Found; return Sources.createFileID(File, SourceLocation(), SrcMgr::C_User); |