summaryrefslogtreecommitdiff
path: root/lib/Basic/SourceManager.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2009-02-04 02:29:52 +0000
committerChris Lattner <sabre@nondot.org>2009-02-04 02:29:52 +0000
commit1c4a49813bcf9e24711e5963ea6b2c27e5113a6e (patch)
tree11a71bfb5e338da90a636c817b395b71ea89af7f /lib/Basic/SourceManager.cpp
parent953b4b0950cb074156d66b45e8dab26725d4bccb (diff)
downloadclang-1c4a49813bcf9e24711e5963ea6b2c27e5113a6e.tar.gz
make my atrocious linear search at least search in the order that is
more likely to hit. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@63714 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Basic/SourceManager.cpp')
-rw-r--r--lib/Basic/SourceManager.cpp9
1 files changed, 4 insertions, 5 deletions
diff --git a/lib/Basic/SourceManager.cpp b/lib/Basic/SourceManager.cpp
index c32264627a..d9cf5e1a54 100644
--- a/lib/Basic/SourceManager.cpp
+++ b/lib/Basic/SourceManager.cpp
@@ -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;
}