Implement caching of stat() calls for precompiled headers, which is
essentially the same thing we do with pretokenized headers. stat()
caching improves performance of the Cocoa-prefixed "Hello, World" by
45%.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@70223 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Basic/FileManager.cpp b/lib/Basic/FileManager.cpp
index 2cd140d..cc25d33 100644
--- a/lib/Basic/FileManager.cpp
+++ b/lib/Basic/FileManager.cpp
@@ -19,6 +19,7 @@
 
 #include "clang/Basic/FileManager.h"
 #include "llvm/ADT/SmallString.h"
+#include "llvm/System/Path.h"
 #include "llvm/Support/Streams.h"
 #include "llvm/Config/config.h"
 using namespace clang;
@@ -282,3 +283,20 @@
   
   //llvm::cerr << PagesMapped << BytesOfPagesMapped << FSLookups;
 }
+
+int MemorizeStatCalls::stat(const char *path, struct stat *buf) {
+  int result = ::stat(path, buf);
+    
+  if (result != 0) { 
+    // Cache failed 'stat' results.
+    struct stat empty;
+    StatCalls[path] = StatResult(result, empty);
+  }
+  else if (!S_ISDIR(buf->st_mode) || llvm::sys::Path(path).isAbsolute()) {
+    // Cache file 'stat' results and directories with absolutely
+    // paths.
+    StatCalls[path] = StatResult(result, *buf);
+  }
+    
+  return result;  
+}