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

Chris Lattner sabre at nondot.org
Tue Nov 23 11:56:39 PST 2010


Author: lattner
Date: Tue Nov 23 13:56:39 2010
New Revision: 120037

URL: http://llvm.org/viewvc/llvm-project?rev=120037&view=rev
Log:
factor the "cache miss" handling code out of FM into a static 
method in FileSystemStatCache.

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

Modified: cfe/trunk/include/clang/Basic/FileSystemStatCache.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/FileSystemStatCache.h?rev=120037&r1=120036&r2=120037&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/FileSystemStatCache.h (original)
+++ cfe/trunk/include/clang/Basic/FileSystemStatCache.h Tue Nov 23 13:56:39 2010
@@ -36,8 +36,21 @@
     CacheHitMissing,  //< We know that the file doesn't exist.
     CacheMiss         //< We don't know anything about the file.
   };
-  
-  virtual LookupResult getStat(const char *Path, struct stat &StatBuf) = 0;
+
+  /// FileSystemStatCache::get - Get the 'stat' information for the specified
+  /// path, using the cache to accellerate it if possible.  This returns true if
+  /// the path does not exist or false if it exists.
+  static bool get(const char *Path, struct stat &StatBuf,
+                  FileSystemStatCache *Cache) {
+    LookupResult R = CacheMiss;
+    
+    if (Cache)
+      R = Cache->getStat(Path, StatBuf);
+    
+    if (R == FileSystemStatCache::CacheMiss)
+      return ::stat(Path, &StatBuf);
+    return R == FileSystemStatCache::CacheHitMissing;
+  }
   
   /// \brief Sets the next stat call cache in the chain of stat caches.
   /// Takes ownership of the given stat cache.
@@ -54,6 +67,8 @@
   FileSystemStatCache *takeNextStatCache() { return NextStatCache.take(); }
   
 protected:
+  virtual LookupResult getStat(const char *Path, struct stat &StatBuf) = 0;
+
   LookupResult statChained(const char *Path, struct stat &StatBuf) {
     if (FileSystemStatCache *Next = getNextStatCache())
       return Next->getStat(Path, StatBuf);

Modified: cfe/trunk/lib/Basic/FileManager.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/FileManager.cpp?rev=120037&r1=120036&r2=120037&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/FileManager.cpp (original)
+++ cfe/trunk/lib/Basic/FileManager.cpp Tue Nov 23 13:56:39 2010
@@ -306,14 +306,12 @@
 
   // Nope, there isn't.  Check to see if the file exists.
   struct stat StatBuf;
-  //llvm::errs() << "STATING: " << Filename;
   if (getStatValue(InterndFileName, StatBuf) ||    // Error stat'ing.
       S_ISDIR(StatBuf.st_mode)) {                  // A directory?
-    // If this file doesn't exist, we leave a null in FileEntries for this path.
-    //llvm::errs() << ": Not existing\n";
+    // If this file doesn't exist, we leave NON_EXISTENT_FILE in FileEntries for
+    // this path so subsequent queries get the negative result.
     return 0;
   }
-  //llvm::errs() << ": exists\n";
 
   // It exists.  See if we have already opened a file with the same inode.
   // This occurs when one dir is symlinked to another, for example.
@@ -416,28 +414,15 @@
 /// cache to accellerate it if possible.  This returns true if the path does not
 /// exist or false if it exists.
 bool FileManager::getStatValue(const char *Path, struct stat &StatBuf) {
-  FileSystemStatCache::LookupResult Result = FileSystemStatCache::CacheMiss;
-  
   // FIXME: FileSystemOpts shouldn't be passed in here, all paths should be
   // absolute!
-  if (FileSystemOpts.WorkingDir.empty()) {
-    if (StatCache.get())
-      Result = StatCache->getStat(Path, StatBuf);
-    
-    if (Result == FileSystemStatCache::CacheMiss)
-      return ::stat(Path, &StatBuf);
-    return Result == FileSystemStatCache::CacheHitMissing;
-  }
+  if (FileSystemOpts.WorkingDir.empty())
+    return FileSystemStatCache::get(Path, StatBuf, StatCache.get());
   
   llvm::sys::Path FilePath(Path);
   FixupRelativePath(FilePath, FileSystemOpts);
-  
-  if (StatCache.get())
-    Result = StatCache->getStat(FilePath.c_str(), StatBuf);
-  
-  if (Result == FileSystemStatCache::CacheMiss)
-    return ::stat(FilePath.c_str(), &StatBuf);
-  return Result == FileSystemStatCache::CacheHitMissing;
+
+  return FileSystemStatCache::get(FilePath.c_str(), StatBuf, StatCache.get());
 }
 
 





More information about the cfe-commits mailing list