PTH: Cache directory and negative 'stat' calls.  This gives us a 1% performance improvement on Cocoa.h (fsyntax-only+PTH).

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@64490 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Lex/PTHLexer.cpp b/lib/Lex/PTHLexer.cpp
index 12fe829..ac510af 100644
--- a/lib/Lex/PTHLexer.cpp
+++ b/lib/Lex/PTHLexer.cpp
@@ -808,15 +808,17 @@
   
   static data_type ReadData(const internal_key_type& k, const unsigned char* d,
                             unsigned) {    
-    if (k.first == 0x1 /* File */) {
-      d += 4 * 2; // Skip the first 2 words.
+    
+    if (k.first /* File or Directory */) {
+      if (k.first == 0x1 /* File */) d += 4 * 2; // Skip the first 2 words.
       ino_t ino = (ino_t) ReadUnalignedLE32(d);
       dev_t dev = (dev_t) ReadUnalignedLE32(d);
       mode_t mode = (mode_t) ReadUnalignedLE16(d);
       time_t mtime = (time_t) ReadUnalignedLE64(d);    
       return data_type(ino, dev, mode, mtime, (off_t) ReadUnalignedLE64(d));
     }
-    
+
+    // Negative stat.  Don't read anything.
     return data_type();
   }
 };
@@ -841,6 +843,10 @@
     if (I == Cache.end()) return ::stat(path, buf);
     
     const PTHStatData& Data = *I;
+    
+    if (!Data.hasStat)
+      return 1;
+
     buf->st_ino = Data.ino;
     buf->st_dev = Data.dev;
     buf->st_mtime = Data.mtime;