summaryrefslogtreecommitdiffstats
path: root/clang/lib/Basic/FileManager.cpp
diff options
context:
space:
mode:
authorDavid Blaikie <dblaikie@gmail.com>2014-11-19 03:06:06 +0000
committerDavid Blaikie <dblaikie@gmail.com>2014-11-19 03:06:06 +0000
commit13156b689e67e2857769f96adad141203d844e16 (patch)
treedcb4058a1a9dd9a0466a5d6ee8eacefc8981358d /clang/lib/Basic/FileManager.cpp
parent8e6cf9e5791083103ea711200b8315520c502adb (diff)
downloadbcm5719-llvm-13156b689e67e2857769f96adad141203d844e16.tar.gz
bcm5719-llvm-13156b689e67e2857769f96adad141203d844e16.zip
Standardize on StringMap::insert, removing uses of StringMap::GetOrCreateValue.
llvm-svn: 222306
Diffstat (limited to 'clang/lib/Basic/FileManager.cpp')
-rw-r--r--clang/lib/Basic/FileManager.cpp69
1 files changed, 35 insertions, 34 deletions
diff --git a/clang/lib/Basic/FileManager.cpp b/clang/lib/Basic/FileManager.cpp
index 91681edcc51..af6022fdc92 100644
--- a/clang/lib/Basic/FileManager.cpp
+++ b/clang/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;
OpenPOWER on IntegriCloud