[cfe-commits] r120048 - /cfe/trunk/lib/Basic/FileManager.cpp

Chris Lattner sabre at nondot.org
Tue Nov 23 12:30:42 PST 2010


Author: lattner
Date: Tue Nov 23 14:30:42 2010
New Revision: 120048

URL: http://llvm.org/viewvc/llvm-project?rev=120048&view=rev
Log:
tidy up code, add a comment about dir caching.

Modified:
    cfe/trunk/lib/Basic/FileManager.cpp

Modified: cfe/trunk/lib/Basic/FileManager.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/FileManager.cpp?rev=120048&r1=120047&r2=120048&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/FileManager.cpp (original)
+++ cfe/trunk/lib/Basic/FileManager.cpp Tue Nov 23 14:30:42 2010
@@ -69,13 +69,10 @@
 public:
   DirectoryEntry &getDirectory(const char *Name, struct stat &StatBuf) {
     std::string FullPath(GetFullPath(Name));
-    return UniqueDirs.GetOrCreateValue(
-                              FullPath.c_str(),
-                              FullPath.c_str() + FullPath.size()
-                                                                ).getValue();
+    return UniqueDirs.GetOrCreateValue(FullPath).getValue();
   }
 
-  size_t size() { return UniqueDirs.size(); }
+  size_t size() const { return UniqueDirs.size(); }
 };
 
 class FileManager::UniqueFileContainer {
@@ -89,13 +86,10 @@
     
     // LowercaseString because Windows filesystem is case insensitive.
     FullPath = llvm::LowercaseString(FullPath);
-    return UniqueFiles.GetOrCreateValue(
-                               FullPath.c_str(),
-                               FullPath.c_str() + FullPath.size()
-                                                                 ).getValue();
+    return UniqueFiles.GetOrCreateValue(FullPath).getValue();
   }
 
-  size_t size() { return UniqueFiles.size(); }
+  size_t size() const { return UniqueFiles.size(); }
 };
 
 //===----------------------------------------------------------------------===//
@@ -116,7 +110,7 @@
     return UniqueDirs[std::make_pair(StatBuf.st_dev, StatBuf.st_ino)];
   }
 
-  size_t size() { return UniqueDirs.size(); }
+  size_t size() const { return UniqueDirs.size(); }
 };
 
 class FileManager::UniqueFileContainer {
@@ -133,7 +127,7 @@
                                                   StatBuf.st_mode)).first);
   }
 
-  size_t size() { return UniqueFiles.size(); }
+  size_t size() const { return UniqueFiles.size(); }
 };
 
 #endif
@@ -144,8 +138,8 @@
 
 FileManager::FileManager(const FileSystemOptions &FSO)
   : FileSystemOpts(FSO),
-    UniqueDirs(*new UniqueDirContainer),
-    UniqueFiles(*new UniqueFileContainer),
+    UniqueDirs(*new UniqueDirContainer()),
+    UniqueFiles(*new UniqueFileContainer()),
     DirEntries(64), FileEntries(64), NextFileUID(0) {
   NumDirLookups = NumFileLookups = 0;
   NumDirCacheMisses = NumFileCacheMisses = 0;
@@ -154,12 +148,8 @@
 FileManager::~FileManager() {
   delete &UniqueDirs;
   delete &UniqueFiles;
-  for (llvm::SmallVectorImpl<FileEntry *>::iterator
-         V = VirtualFileEntries.begin(),
-         VEnd = VirtualFileEntries.end();
-       V != VEnd; 
-       ++V)
-    delete *V;
+  for (unsigned i = 0, e = VirtualFileEntries.size(); i != e; ++i)
+    delete VirtualFileEntries[i];
 }
 
 void FileManager::addStatCache(FileSystemStatCache *statCache,
@@ -297,6 +287,12 @@
   // FileEntries map.
   const char *InterndFileName = NamedFileEnt.getKeyData();
 
+  
+  // 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'
+  // subdirectory.  This will let us avoid having to waste time on known-to-fail
+  // searches when we go to find sys/bar.h, because all the search directories
+  // without a 'sys' subdir will get a cached failure result.
   const DirectoryEntry *DirInfo = getDirectoryFromFile(*this, Filename);
   if (DirInfo == 0)  // Directory doesn't exist, file can't exist.
     return 0;





More information about the cfe-commits mailing list