[cfe-commits] r40460 - /cfe/trunk/Basic/SourceManager.cpp
Chris Lattner
sabre at nondot.org
Mon Jul 23 23:43:46 PDT 2007
Author: lattner
Date: Tue Jul 24 01:43:46 2007
New Revision: 40460
URL: http://llvm.org/viewvc/llvm-project?rev=40460&view=rev
Log:
check in an experiment that didn't work out, to allow for future investigation.
Modified:
cfe/trunk/Basic/SourceManager.cpp
Modified: cfe/trunk/Basic/SourceManager.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Basic/SourceManager.cpp?rev=40460&r1=40459&r2=40460&view=diff
==============================================================================
--- cfe/trunk/Basic/SourceManager.cpp (original)
+++ cfe/trunk/Basic/SourceManager.cpp Tue Jul 24 01:43:46 2007
@@ -337,11 +337,33 @@
}
}
- unsigned *Pos;
- // TODO: If this is performance sensitive, we could try doing simple radix
- // type approaches to make good (tight?) initial guesses based on the
- // assumption that all lines are the same average size.
- Pos = std::lower_bound(SourceLineCache, SourceLineCacheEnd, QueriedFilePos);
+ // If the spread is large, do a "radix" test as our initial guess, based on
+ // the assumption that lines average to approximately the same length.
+ // NOTE: This is currently disabled, as it does not appear to be profitable in
+ // initial measurements.
+ if (0 && SourceLineCacheEnd-SourceLineCache > 20) {
+ unsigned FileLen = FileInfo->SourceLineCache[FileInfo->NumLines-1];
+
+ // Take a stab at guessing where it is.
+ unsigned ApproxPos = FileInfo->NumLines*QueriedFilePos / FileLen;
+
+ // Check for -10 and +10 lines.
+ unsigned LowerBound = std::max(int(ApproxPos-10), 0);
+ unsigned UpperBound = std::min(ApproxPos+10, FileLen);
+
+ // If the computed lower bound is less than the query location, move it in.
+ if (SourceLineCache < SourceLineCacheStart+LowerBound &&
+ SourceLineCacheStart[LowerBound] < QueriedFilePos)
+ SourceLineCache = SourceLineCacheStart+LowerBound;
+
+ // If the computed upper bound is greater than the query location, move it.
+ if (SourceLineCacheEnd > SourceLineCacheStart+UpperBound &&
+ SourceLineCacheStart[UpperBound] >= QueriedFilePos)
+ SourceLineCacheEnd = SourceLineCacheStart+UpperBound;
+ }
+
+ unsigned *Pos
+ = std::lower_bound(SourceLineCache, SourceLineCacheEnd, QueriedFilePos);
unsigned LineNo = Pos-SourceLineCacheStart;
LastLineNoFileIDQuery = FileID;
More information about the cfe-commits
mailing list