]> granicus.if.org Git - clang/commitdiff
Teach getColumnNumber to use the line cache to get the start of the line if its on...
authorCraig Topper <craig.topper@gmail.com>
Fri, 19 Oct 2012 04:40:38 +0000 (04:40 +0000)
committerCraig Topper <craig.topper@gmail.com>
Fri, 19 Oct 2012 04:40:38 +0000 (04:40 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@166265 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Basic/SourceManager.cpp

index eefaacc7c3dbac7a18e22fddf1a1a6c05e88c3e5..603b38592603ef1bb849925383b3a4d82ec5af8a 100644 (file)
@@ -1029,6 +1029,17 @@ unsigned SourceManager::getColumnNumber(FileID FID, unsigned FilePos,
     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 &&
+      LastLineNoContentCache->SourceLineCache != 0) {
+    unsigned *SourceLineCache = LastLineNoContentCache->SourceLineCache;
+    unsigned LineStart = SourceLineCache[LastLineNoResult - 1];
+    unsigned LineEnd = SourceLineCache[LastLineNoResult];
+    if (FilePos >= LineStart && FilePos < LineEnd)
+      return FilePos - LineStart + 1;
+  }
+
   const char *Buf = MemBuf->getBufferStart();
   unsigned LineStart = FilePos;
   while (LineStart && Buf[LineStart-1] != '\n' && Buf[LineStart-1] != '\r')