File tree Expand file tree Collapse file tree 2 files changed +7
-2
lines changed Expand file tree Collapse file tree 2 files changed +7
-2
lines changed Original file line number Diff line number Diff line change @@ -1903,7 +1903,7 @@ class SourceManager : public RefCountedBase<SourceManager> {
19031903
19041904 FileID getFileID (SourceLocation::UIntTy SLocOffset) const {
19051905 // If our one-entry cache covers this offset, just return it.
1906- if (SLocOffset >= LastLookupStartOffset && SLocOffset < LastLookupEndOffset )
1906+ if (isOffsetInFileID (LastFileIDLookup, SLocOffset) )
19071907 return LastFileIDLookup;
19081908 return getFileIDSlow (SLocOffset);
19091909 }
@@ -1927,6 +1927,10 @@ class SourceManager : public RefCountedBase<SourceManager> {
19271927 // / specified SourceLocation offset. This is a very hot method.
19281928 inline bool isOffsetInFileID (FileID FID,
19291929 SourceLocation::UIntTy SLocOffset) const {
1930+ if (FID == LastFileIDLookup)
1931+ return SLocOffset >= LastLookupStartOffset &&
1932+ SLocOffset < LastLookupEndOffset;
1933+
19301934 const SrcMgr::SLocEntry &Entry = getSLocEntry (FID);
19311935 // If the entry is after the offset, it can't contain it.
19321936 if (SLocOffset < Entry.getOffset ()) return false ;
Original file line number Diff line number Diff line change @@ -814,8 +814,9 @@ FileID SourceManager::getFileIDSlow(SourceLocation::UIntTy SLocOffset) const {
814814// / loaded one.
815815FileID SourceManager::getFileIDLocal (SourceLocation::UIntTy SLocOffset) const {
816816 assert (SLocOffset < NextLocalOffset && " Bad function choice" );
817- assert (SLocOffset >= LocalSLocEntryTable[0 ].getOffset () &&
817+ assert (SLocOffset >= LocalSLocEntryTable[0 ].getOffset () && SLocOffset > 0 &&
818818 " Invalid SLocOffset" );
819+ assert (LastFileIDLookup.ID >= 0 && " Only cache local file sloc entry" );
819820
820821 // After the first and second level caches, I see two common sorts of
821822 // behavior: 1) a lot of searched FileID's are "near" the cached file
You can’t perform that action at this time.
0 commit comments