]> granicus.if.org Git - clang/commitdiff
simplify the cache miss handling code, eliminating CacheMissing.
authorChris Lattner <sabre@nondot.org>
Tue, 23 Nov 2010 20:05:15 +0000 (20:05 +0000)
committerChris Lattner <sabre@nondot.org>
Tue, 23 Nov 2010 20:05:15 +0000 (20:05 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@120038 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/FileSystemStatCache.h
lib/Basic/FileSystemStatCache.cpp
lib/Frontend/CacheTokens.cpp
lib/Lex/PTHLexer.cpp
lib/Serialization/ASTReader.cpp

index 7bb3706793153f9aeef93fdcb35945afbc740f51..e9da8cf15c00618daea2bca835f978d58fab82ad 100644 (file)
@@ -32,9 +32,8 @@ public:
   virtual ~FileSystemStatCache() {}
   
   enum LookupResult {
-    CacheHitExists,   //< We know the file exists and its cached stat data.
-    CacheHitMissing,  //< We know that the file doesn't exist.
-    CacheMiss         //< We don't know anything about the file.
+    CacheExists,   //< We know the file exists and its cached stat data.
+    CacheMissing   //< We know that the file doesn't exist.
   };
 
   /// FileSystemStatCache::get - Get the 'stat' information for the specified
@@ -42,14 +41,10 @@ public:
   /// 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);
+      return Cache->getStat(Path, StatBuf) == CacheMissing;
     
-    if (R == FileSystemStatCache::CacheMiss)
-      return ::stat(Path, &StatBuf);
-    return R == FileSystemStatCache::CacheHitMissing;
+    return ::stat(Path, &StatBuf) != 0;
   }
   
   /// \brief Sets the next stat call cache in the chain of stat caches.
@@ -73,7 +68,9 @@ protected:
     if (FileSystemStatCache *Next = getNextStatCache())
       return Next->getStat(Path, StatBuf);
     
-    return CacheMiss;
+    // If we hit the end of the list of stat caches to try, just compute and
+    // return it without a cache.
+    return get(Path, StatBuf, 0) ? CacheMissing : CacheExists;
   }
 };
 
index 738af41a9eeb6c1d3848798e225229cbc55fba18..26e9d2f15018cf1a6d1c5ea6544e69a8c0549461 100644 (file)
@@ -19,16 +19,11 @@ MemorizeStatCalls::LookupResult
 MemorizeStatCalls::getStat(const char *Path, struct stat &StatBuf) {
   LookupResult Result = statChained(Path, StatBuf);
   
-  // If the chained cache didn't know anything about the file, do the stat now
-  // so we can record the result.
-  if (Result == CacheMiss)
-    Result = ::stat(Path, &StatBuf) ? CacheHitMissing : CacheHitExists;
-  
   // Do not cache failed stats, it is easy to construct common inconsistent
   // situations if we do, and they are not important for PCH performance (which
   // currently only needs the stats to construct the initial FileManager
   // entries).
-  if (Result == CacheHitMissing)
+  if (Result == CacheMissing)
     return Result;
   
   // Cache file 'stat' results and directories with absolutely paths.
index 94bee6b868b88ec2f7b8c429d6c7e4cba30b41d2..2a7af8a8c352f53b963175d3a9a0f1dd4f500142 100644 (file)
@@ -518,14 +518,9 @@ public:
   ~StatListener() {}
 
   LookupResult getStat(const char *Path, struct stat &StatBuf) {
-    LookupResult Result = FileSystemStatCache::statChained(Path, StatBuf);
-
-    // If the chained cache didn't know anything about the file, do the stat now
-    // so we can record the result.
-    if (Result == CacheMiss)
-      Result = ::stat(Path, &StatBuf) ? CacheHitMissing : CacheHitExists;
-    
-    if (Result == CacheHitMissing) // Failed 'stat'.
+    LookupResult Result = statChained(Path, StatBuf);
+
+    if (Result == CacheMissing) // Failed 'stat'.
       PM.insert(PTHEntryKeyVariant(Path), PTHEntry());
     else if (S_ISDIR(StatBuf.st_mode)) {
       // Only cache directories with absolute paths.
index 0dd30f6d701db2335dd1755ad6647e92551ae02d..ed068675fe323a8d0b23d0dcc8ed9c4925dfed4a 100644 (file)
@@ -26,7 +26,6 @@
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringMap.h"
 #include "llvm/Support/MemoryBuffer.h"
-#include <sys/stat.h>
 using namespace clang;
 using namespace clang::io;
 
@@ -690,14 +689,14 @@ public:
     const PTHStatData &Data = *I;
 
     if (!Data.hasStat)
-      return CacheHitMissing;
+      return CacheMissing;
 
     StatBuf.st_ino = Data.ino;
     StatBuf.st_dev = Data.dev;
     StatBuf.st_mtime = Data.mtime;
     StatBuf.st_mode = Data.mode;
     StatBuf.st_size = Data.size;
-    return CacheHitExists;
+    return CacheExists;
   }
 };
 } // end anonymous namespace
index 0c0e4fffc05b9a80f5ab6b618fe36cd015e04725..dc719a1f938a3e7f6490cd5fb94386ec99d7017e 100644 (file)
@@ -1092,7 +1092,7 @@ public:
     StatBuf.st_mtime = Data.mtime;
     StatBuf.st_mode = Data.mode;
     StatBuf.st_size = Data.size;
-    return CacheHitExists;
+    return CacheExists;
   }
 };
 } // end anonymous namespace