Eliminate the unnecessary FirstFID cache variable from the source manager's ContentCache

llvm-svn: 90294
This commit is contained in:
Douglas Gregor 2009-12-02 05:34:39 +00:00
parent 4ca1981e82
commit 2a1b691622
2 changed files with 27 additions and 11 deletions

View File

@ -72,11 +72,6 @@ namespace SrcMgr {
/// if SourceLineCache is non-null. /// if SourceLineCache is non-null.
unsigned NumLines; unsigned NumLines;
/// FirstFID - First FileID that was created for this ContentCache.
/// Represents the first source inclusion of the file associated with this
/// ContentCache.
mutable FileID FirstFID;
/// getBuffer - Returns the memory buffer for the associated content. If /// getBuffer - Returns the memory buffer for the associated content. If
/// there is an error opening this buffer the first time, this returns null /// there is an error opening this buffer the first time, this returns null
/// and fills in the ErrorStr with a reason. /// and fills in the ErrorStr with a reason.

View File

@ -413,8 +413,6 @@ FileID SourceManager::createFileID(const ContentCache *File,
= SLocEntry::get(Offset, FileInfo::get(IncludePos, File, FileCharacter)); = SLocEntry::get(Offset, FileInfo::get(IncludePos, File, FileCharacter));
SLocEntryLoaded[PreallocatedID] = true; SLocEntryLoaded[PreallocatedID] = true;
FileID FID = FileID::get(PreallocatedID); FileID FID = FileID::get(PreallocatedID);
if (File->FirstFID.isInvalid())
File->FirstFID = FID;
return LastFileIDLookup = FID; return LastFileIDLookup = FID;
} }
@ -428,8 +426,6 @@ FileID SourceManager::createFileID(const ContentCache *File,
// Set LastFileIDLookup to the newly created file. The next getFileID call is // Set LastFileIDLookup to the newly created file. The next getFileID call is
// almost guaranteed to be from that file. // almost guaranteed to be from that file.
FileID FID = FileID::get(SLocEntryTable.size()-1); FileID FID = FileID::get(SLocEntryTable.size()-1);
if (File->FirstFID.isInvalid())
File->FirstFID = FID;
return LastFileIDLookup = FID; return LastFileIDLookup = FID;
} }
@ -1007,8 +1003,33 @@ SourceLocation SourceManager::getLocation(const FileEntry *SourceFile,
if (i < Col-1) if (i < Col-1)
return SourceLocation(); return SourceLocation();
return getLocForStartOfFile(Content->FirstFID). // Find the first file ID that corresponds to the given file.
getFileLocWithOffset(FilePos + Col - 1); FileID FirstFID;
// First, check the main file ID, since it is common to look for a
// location in the main file.
if (!MainFileID.isInvalid()) {
const SLocEntry &MainSLoc = getSLocEntry(MainFileID);
if (MainSLoc.isFile() && MainSLoc.getFile().getContentCache() == Content)
FirstFID = MainFileID;
}
if (FirstFID.isInvalid()) {
// The location we're looking for isn't in the main file; look
// through all of the source locations.
for (unsigned I = 0, N = sloc_entry_size(); I != N; ++I) {
const SLocEntry &SLoc = getSLocEntry(I);
if (SLoc.isFile() && SLoc.getFile().getContentCache() == Content) {
FirstFID = FileID::get(I);
break;
}
}
}
if (FirstFID.isInvalid())
return SourceLocation();
return getLocForStartOfFile(FirstFID).getFileLocWithOffset(FilePos + Col - 1);
} }
/// \brief Determines the order of 2 source locations in the translation unit. /// \brief Determines the order of 2 source locations in the translation unit.