@@ -328,6 +328,7 @@ SourceManager::~SourceManager() {
328
328
void SourceManager::clearIDTables () {
329
329
MainFileID = FileID ();
330
330
LocalSLocEntryTable.clear ();
331
+ LocalLocOffsetTable.clear ();
331
332
LoadedSLocEntryTable.clear ();
332
333
SLocEntryLoaded.clear ();
333
334
SLocEntryOffsetLoaded.clear ();
@@ -636,9 +637,11 @@ FileID SourceManager::createFileIDImpl(ContentCache &File, StringRef Filename,
636
637
noteSLocAddressSpaceUsage (Diag);
637
638
return FileID ();
638
639
}
640
+ assert (LocalSLocEntryTable.size () == LocalLocOffsetTable.size ());
639
641
LocalSLocEntryTable.push_back (
640
642
SLocEntry::get (NextLocalOffset,
641
643
FileInfo::get (IncludePos, File, FileCharacter, Filename)));
644
+ LocalLocOffsetTable.push_back (NextLocalOffset);
642
645
// We do a +1 here because we want a SourceLocation that means "the end of the
643
646
// file", e.g. for the "no newline at the end of the file" diagnostic.
644
647
NextLocalOffset += FileSize + 1 ;
@@ -690,7 +693,9 @@ SourceManager::createExpansionLocImpl(const ExpansionInfo &Info,
690
693
SLocEntryLoaded[Index] = SLocEntryOffsetLoaded[Index] = true ;
691
694
return SourceLocation::getMacroLoc (LoadedOffset);
692
695
}
696
+ assert (LocalSLocEntryTable.size () == LocalLocOffsetTable.size ());
693
697
LocalSLocEntryTable.push_back (SLocEntry::get (NextLocalOffset, Info));
698
+ LocalLocOffsetTable.push_back (NextLocalOffset);
694
699
if (NextLocalOffset + Length + 1 <= NextLocalOffset ||
695
700
NextLocalOffset + Length + 1 > CurrentLoadedOffset) {
696
701
Diag.Report (diag::err_sloc_space_too_large);
@@ -813,7 +818,7 @@ FileID SourceManager::getFileIDLocal(SourceLocation::UIntTy SLocOffset) const {
813
818
assert (SLocOffset < NextLocalOffset && " Bad function choice" );
814
819
assert (SLocOffset >= LocalSLocEntryTable[0 ].getOffset () &&
815
820
" Invalid SLocOffset" );
816
-
821
+ assert (LocalSLocEntryTable. size () == LocalLocOffsetTable. size ());
817
822
// After the first and second level caches, I see two common sorts of
818
823
// behavior: 1) a lot of searched FileID's are "near" the cached file
819
824
// location or are "near" the cached expansion location. 2) others are just
@@ -831,10 +836,10 @@ FileID SourceManager::getFileIDLocal(SourceLocation::UIntTy SLocOffset) const {
831
836
// SLocOffset.
832
837
unsigned LessIndex = 0 ;
833
838
// upper bound of the search range.
834
- unsigned GreaterIndex = LocalSLocEntryTable .size ();
839
+ unsigned GreaterIndex = LocalLocOffsetTable .size ();
835
840
if (LastFileIDLookup.ID >= 0 ) {
836
841
// Use the LastFileIDLookup to prune the search space.
837
- if (LocalSLocEntryTable [LastFileIDLookup.ID ]. getOffset () < SLocOffset)
842
+ if (LocalLocOffsetTable [LastFileIDLookup.ID ] < SLocOffset)
838
843
LessIndex = LastFileIDLookup.ID ;
839
844
else
840
845
GreaterIndex = LastFileIDLookup.ID ;
@@ -844,8 +849,8 @@ FileID SourceManager::getFileIDLocal(SourceLocation::UIntTy SLocOffset) const {
844
849
unsigned NumProbes = 0 ;
845
850
while (true ) {
846
851
--GreaterIndex;
847
- assert (GreaterIndex < LocalSLocEntryTable .size ());
848
- if (LocalSLocEntryTable [GreaterIndex]. getOffset () <= SLocOffset) {
852
+ assert (GreaterIndex < LocalLocOffsetTable .size ());
853
+ if (LocalLocOffsetTable [GreaterIndex] <= SLocOffset) {
849
854
FileID Res = FileID::get (int (GreaterIndex));
850
855
// Remember it. We have good locality across FileID lookups.
851
856
LastFileIDLookup = Res;
@@ -860,11 +865,7 @@ FileID SourceManager::getFileIDLocal(SourceLocation::UIntTy SLocOffset) const {
860
865
++NumBinaryProbes;
861
866
862
867
unsigned MiddleIndex = LessIndex + (GreaterIndex - LessIndex) / 2 ;
863
-
864
- SourceLocation::UIntTy MidOffset =
865
- LocalSLocEntryTable[MiddleIndex].getOffset ();
866
-
867
- if (MidOffset <= SLocOffset)
868
+ if (LocalLocOffsetTable[MiddleIndex] <= SLocOffset)
868
869
LessIndex = MiddleIndex + 1 ;
869
870
else
870
871
GreaterIndex = MiddleIndex;
0 commit comments