[cfe-commits] r39082 - in /cfe/cfe/trunk: Basic/FileManager.cpp include/clang/Basic/FileManager.h

sabre at cs.uiuc.edu sabre at cs.uiuc.edu
Wed Jul 11 09:27:23 PDT 2007


Author: sabre
Date: Wed Jul 11 11:27:23 2007
New Revision: 39082

URL: http://llvm.org/viewvc/llvm-project?rev=39082&view=rev
Log:
Switch DirEntries over to using a CStringMap.  This speeds it up
'clang -Eonly INPUTS/Cocoa_h.m' by about 4%.

Modified:
    cfe/cfe/trunk/Basic/FileManager.cpp
    cfe/cfe/trunk/include/clang/Basic/FileManager.h

Modified: cfe/cfe/trunk/Basic/FileManager.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Basic/FileManager.cpp?rev=39082&r1=39081&r2=39082&view=diff

==============================================================================
--- cfe/cfe/trunk/Basic/FileManager.cpp (original)
+++ cfe/cfe/trunk/Basic/FileManager.cpp Wed Jul 11 11:27:23 2007
@@ -25,24 +25,30 @@
 // 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 @@
     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

Modified: cfe/cfe/trunk/include/clang/Basic/FileManager.h
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/include/clang/Basic/FileManager.h?rev=39082&r1=39081&r2=39082&view=diff

==============================================================================
--- cfe/cfe/trunk/include/clang/Basic/FileManager.h (original)
+++ cfe/cfe/trunk/include/clang/Basic/FileManager.h Wed Jul 11 11:27:23 2007
@@ -14,6 +14,7 @@
 #ifndef LLVM_CLANG_FILEMANAGER_H
 #define LLVM_CLANG_FILEMANAGER_H
 
+#include "llvm/ADT/CStringMap.h"
 #include <map>
 #include <string>
 // FIXME: Enhance libsystem to support inode and other fields in stat.
@@ -70,7 +71,7 @@
   /// DirEntries/FileEntries - This is a cache of directory/file entries we have
   /// looked up.  The actual Entry is owned by UniqueFiles/UniqueDirs above.
   ///
-  std::map<std::string, DirectoryEntry*> DirEntries;
+  CStringMap<DirectoryEntry*> DirEntries;
   std::map<std::string, FileEntry*> FileEntries;
   
   /// NextFileUID - Each FileEntry we create is assigned a unique ID #.





More information about the cfe-commits mailing list