aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Basic/SourceManager.cpp
diff options
context:
space:
mode:
authorCraig Topper <craig.topper@gmail.com>2012-10-19 04:40:38 +0000
committerCraig Topper <craig.topper@gmail.com>2012-10-19 04:40:38 +0000
commit5e79ee087e9eacc311d4abca736c734fb1012f18 (patch)
treed581f133d4d624bce7c757fdd4052432712f3f8e /clang/lib/Basic/SourceManager.cpp
parent4985ddc5e011a9ebde17788fb49d603dcc36aa19 (diff)
downloadllvm-5e79ee087e9eacc311d4abca736c734fb1012f18.zip
llvm-5e79ee087e9eacc311d4abca736c734fb1012f18.tar.gz
llvm-5e79ee087e9eacc311d4abca736c734fb1012f18.tar.bz2
Teach getColumnNumber to use the line cache to get the start of the line if its on the same line as the last call to getLineNumber. Prevents needing to scan backwards for the new line. Fixes PR14106.
llvm-svn: 166265
Diffstat (limited to 'clang/lib/Basic/SourceManager.cpp')
-rw-r--r--clang/lib/Basic/SourceManager.cpp11
1 files changed, 11 insertions, 0 deletions
diff --git a/clang/lib/Basic/SourceManager.cpp b/clang/lib/Basic/SourceManager.cpp
index eefaacc..603b385 100644
--- a/clang/lib/Basic/SourceManager.cpp
+++ b/clang/lib/Basic/SourceManager.cpp
@@ -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')