]> granicus.if.org Git - clang/commitdiff
make my atrocious linear search at least search in the order that is
authorChris Lattner <sabre@nondot.org>
Wed, 4 Feb 2009 02:29:52 +0000 (02:29 +0000)
committerChris Lattner <sabre@nondot.org>
Wed, 4 Feb 2009 02:29:52 +0000 (02:29 +0000)
more likely to hit.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@63714 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Basic/SourceManager.cpp

index c32264627aee6d5b60f856e7b47119a9f8775f11..d9cf5e1a54b32d82ff6663180d8944fac54248fd 100644 (file)
@@ -160,14 +160,13 @@ const LineEntry *LineTableInfo::FindNearestLineEntry(unsigned FID,
   const std::vector<LineEntry> &Entries = LineEntries[FID];
   assert(!Entries.empty() && "No #line entries for this FID after all!");
 
-  if (Entries[0].FileOffset > Offset) return 0;
 
   // FIXME: Dumb linear search.
   // Find the maximal element that is still before Offset.
-  for (unsigned i = 1, e = Entries.size(); i != e; ++i)
-    if (Entries[i].FileOffset > Offset) return &Entries[i-1];
-  // Otherwise, all entries are before Offset.
-  return &Entries.back();
+  for (std::vector<LineEntry>::const_reverse_iterator I = Entries.rbegin(),
+       E = Entries.rend(); I != E; ++I)
+    if (I->FileOffset <= Offset) return &*I;
+  return 0;
 }