[cfe-commits] r63714 - /cfe/trunk/lib/Basic/SourceManager.cpp

Chris Lattner sabre at nondot.org
Tue Feb 3 18:29:52 PST 2009


Author: lattner
Date: Tue Feb  3 20:29:52 2009
New Revision: 63714

URL: http://llvm.org/viewvc/llvm-project?rev=63714&view=rev
Log:
make my atrocious linear search at least search in the order that is
more likely to hit.

Modified:
    cfe/trunk/lib/Basic/SourceManager.cpp

Modified: cfe/trunk/lib/Basic/SourceManager.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/SourceManager.cpp?rev=63714&r1=63713&r2=63714&view=diff

==============================================================================
--- cfe/trunk/lib/Basic/SourceManager.cpp (original)
+++ cfe/trunk/lib/Basic/SourceManager.cpp Tue Feb  3 20:29:52 2009
@@ -160,14 +160,13 @@
   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;
 }
 
 





More information about the cfe-commits mailing list