summaryrefslogtreecommitdiffstats
path: root/clang/Basic/FileManager.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2006-10-30 03:06:54 +0000
committerChris Lattner <sabre@nondot.org>2006-10-30 03:06:54 +0000
commitaf653759440d53910ffe95d0519bf7c6cc3966a8 (patch)
treee331bb0abb9063405b6524f480dd6fc4fb65143b /clang/Basic/FileManager.cpp
parent8b1e848a043179f0d147c31b65dd8ec977c8bd25 (diff)
downloadbcm5719-llvm-af653759440d53910ffe95d0519bf7c6cc3966a8.tar.gz
bcm5719-llvm-af653759440d53910ffe95d0519bf7c6cc3966a8.zip
Switch DirEntries over to using a CStringMap. This speeds it up
'clang -Eonly INPUTS/Cocoa_h.m' by about 4%. llvm-svn: 39082
Diffstat (limited to 'clang/Basic/FileManager.cpp')
-rw-r--r--clang/Basic/FileManager.cpp26
1 files changed, 16 insertions, 10 deletions
diff --git a/clang/Basic/FileManager.cpp b/clang/Basic/FileManager.cpp
index b0ec368c460..c1520c80e44 100644
--- a/clang/Basic/FileManager.cpp
+++ b/clang/Basic/FileManager.cpp
@@ -25,24 +25,30 @@ using namespace clang;
// FIXME: Enhance libsystem to support inode and other fields.
#include <sys/stat.h>
+
+/// NON_EXISTANT_DIR - A special value distinct from null that is used to
+/// represent a dir name that doesn't exist on the disk.
+#define NON_EXISTANT_DIR reinterpret_cast<DirectoryEntry*>((intptr_t)-1)
+
/// getDirectory - Lookup, cache, and verify the specified directory. This
/// returns null if the directory doesn't exist.
///
const DirectoryEntry *FileManager::getDirectory(const std::string &Filename) {
++NumDirLookups;
+
+ DirectoryEntry *&NamedDirEnt =
+ DirEntries.GetOrCreateValue(&Filename[0], &Filename[0] + Filename.size());
+
// See if there is already an entry in the map.
- std::map<std::string, DirectoryEntry*>::iterator I =
- DirEntries.lower_bound(Filename);
- if (I != DirEntries.end() && I->first == Filename)
- return I->second;
+ if (NamedDirEnt)
+ return NamedDirEnt == NON_EXISTANT_DIR ? 0 : NamedDirEnt;
++NumDirCacheMisses;
- // By default, zero initialize it.
- DirectoryEntry *&Ent =
- DirEntries.insert(I, std::make_pair(Filename, (DirectoryEntry*)0))->second;
+ // By default, initialize it to invalid.
+ NamedDirEnt = NON_EXISTANT_DIR;
- // Nope, there isn't. Check to see if the directory exists.
+ // Check to see if the directory exists.
struct stat StatBuf;
if (stat(Filename.c_str(), &StatBuf) || // Error stat'ing.
!S_ISDIR(StatBuf.st_mode)) // Not a directory?
@@ -54,11 +60,11 @@ const DirectoryEntry *FileManager::getDirectory(const std::string &Filename) {
UniqueDirs[std::make_pair(StatBuf.st_dev, StatBuf.st_ino)];
if (UDE.getName()[0]) // Already have an entry with this inode, return it.
- return Ent = &UDE;
+ return NamedDirEnt = &UDE;
// Otherwise, we don't have this directory yet, add it.
UDE.Name = Filename;
- return Ent = &UDE;
+ return NamedDirEnt = &UDE;
}
/// getFile - Lookup, cache, and verify the specified file. This returns null
OpenPOWER on IntegriCloud