]> granicus.if.org Git - clang/commitdiff
check in an experiment that didn't work out, to allow for future investigation.
authorChris Lattner <sabre@nondot.org>
Tue, 24 Jul 2007 06:43:46 +0000 (06:43 +0000)
committerChris Lattner <sabre@nondot.org>
Tue, 24 Jul 2007 06:43:46 +0000 (06:43 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@40460 91177308-0d34-0410-b5e6-96231b3b80d8

Basic/SourceManager.cpp

index 05ead2d786f3a8280fcb810e447f615a5738b2ec..e53547087df01bb49932a078c96a60819cbcc8d3 100644 (file)
@@ -337,11 +337,33 @@ unsigned SourceManager::getLineNumber(SourceLocation Loc) {
     }
   }
   
-  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;