Index: lib/Basic/SourceManager.cpp
===================================================================
--- lib/Basic/SourceManager.cpp	(revision 166085)
+++ lib/Basic/SourceManager.cpp	(working copy)
@@ -1029,6 +1029,16 @@
     return 1;
   }
 
+  // See if we just calculated the line number for this FilePos and can use
+  // that to lookup the start of the line instead of searching for it.
+  if (LastLineNoFileIDQuery == FID && LastLineNoFilePos == (FilePos + 1)) {
+    if (LastLineNoContentCache->SourceLineCache != 0) {
+      unsigned *SourceLineCache = LastLineNoContentCache->SourceLineCache;
+      unsigned LineStart = SourceLineCache[LastLineNoResult - 1];
+      return FilePos - LineStart + 1;
+    }
+  }
+
   const char *Buf = MemBuf->getBufferStart();
   unsigned LineStart = FilePos;
   while (LineStart && Buf[LineStart-1] != '\n' && Buf[LineStart-1] != '\r')
