diff --git a/clang/lib/Basic/SourceManager.cpp b/clang/lib/Basic/SourceManager.cpp --- a/clang/lib/Basic/SourceManager.cpp +++ b/clang/lib/Basic/SourceManager.cpp @@ -790,15 +790,20 @@ // See if this is near the file point - worst case we start scanning from the // most newly created FileID. - const SrcMgr::SLocEntry *I; - if (LastFileIDLookup.ID < 0 || - LocalSLocEntryTable[LastFileIDLookup.ID].getOffset() < SLocOffset) { - // Neither loc prunes our search. - I = LocalSLocEntryTable.end(); - } else { - // Perhaps it is near the file point. - I = LocalSLocEntryTable.begin()+LastFileIDLookup.ID; + // "I" is an iterator that points to a FileID whose offset is known to be + // larger than SLocOffset. + const SrcMgr::SLocEntry *I = LocalSLocEntryTable.end(); + // LessIndex - This is the lower bound of the range that we're searching. + // We know that the offset corresponding to the FileID is is less than + // SLocOffset. + unsigned LessIndex = 0; + if (LastFileIDLookup.ID >= 0) { + // Use the LastFileIDLookup to prune the search space. + if (LocalSLocEntryTable[LastFileIDLookup.ID].getOffset() < SLocOffset) + LessIndex = LastFileIDLookup.ID; + else + I = LocalSLocEntryTable.begin() + LastFileIDLookup.ID; } // Find the FileID that contains this. "I" is an iterator that points to a @@ -820,10 +825,6 @@ // Convert "I" back into an index. We know that it is an entry whose index is // larger than the offset we are looking for. unsigned GreaterIndex = I - LocalSLocEntryTable.begin(); - // LessIndex - This is the lower bound of the range that we're searching. - // We know that the offset corresponding to the FileID is is less than - // SLocOffset. - unsigned LessIndex = 0; NumProbes = 0; while (true) { unsigned MiddleIndex = (GreaterIndex-LessIndex)/2+LessIndex;