]> granicus.if.org Git - clang/commitdiff
Use a little binary header in serialized diagnostics to help the deserializer skip...
authorDouglas Gregor <dgregor@apple.com>
Fri, 19 Feb 2010 00:40:40 +0000 (00:40 +0000)
committerDouglas Gregor <dgregor@apple.com>
Fri, 19 Feb 2010 00:40:40 +0000 (00:40 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@96641 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Basic/Diagnostic.cpp

index c5c9ca7484e9edcebd4c438c44a29a01baa56bfe..f7ec873e4c156e06d1b20936563faf60e32fe889 100644 (file)
@@ -978,6 +978,9 @@ void StoredDiagnostic::Serialize(llvm::raw_ostream &OS) const {
   if (getLocation().isValid())
     SM = &const_cast<SourceManager &>(getLocation().getManager());
 
+  // Write a short header to help identify diagnostics.
+  OS << (char)0x06 << (char)0x07;
+  
   // Write the diagnostic level and location.
   WriteUnsigned(OS, (unsigned)Level);
   WriteSourceLocation(OS, SM, getLocation());
@@ -1086,9 +1089,29 @@ static bool ReadSourceLocation(FileManager &FM, SourceManager &SM,
 StoredDiagnostic 
 StoredDiagnostic::Deserialize(FileManager &FM, SourceManager &SM, 
                               const char *&Memory, const char *MemoryEnd) {
-  if (Memory == MemoryEnd)
-    return StoredDiagnostic();
-
+  while (true) {
+    if (Memory == MemoryEnd)
+      return StoredDiagnostic();
+    
+    if (*Memory != 0x06) {
+      ++Memory;
+      continue;
+    }
+    
+    ++Memory;
+    if (Memory == MemoryEnd)
+      return StoredDiagnostic();
+  
+    if (*Memory != 0x07) {
+      ++Memory;
+      continue;
+    }
+    
+    // We found the header. We're done.
+    ++Memory;
+    break;
+  }
+  
   // Read the severity level.
   unsigned Level = 0;
   if (ReadUnsigned(Memory, MemoryEnd, Level) || Level > Diagnostic::Fatal)