diff options
author | Douglas Gregor <dgregor@apple.com> | 2009-12-02 05:34:39 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2009-12-02 05:34:39 +0000 |
commit | 2a1b6916226f2b70b1bb8ddc7db9bbde6836aeac (patch) | |
tree | 045a3f0401bb2401586ca44ac4a478fa1b9eb51c /clang/lib/Basic/SourceManager.cpp | |
parent | 4ca1981e820c95dcf9c8e1743c7cbf324273b261 (diff) | |
download | bcm5719-llvm-2a1b6916226f2b70b1bb8ddc7db9bbde6836aeac.tar.gz bcm5719-llvm-2a1b6916226f2b70b1bb8ddc7db9bbde6836aeac.zip |
Eliminate the unnecessary FirstFID cache variable from the source manager's ContentCache
llvm-svn: 90294
Diffstat (limited to 'clang/lib/Basic/SourceManager.cpp')
-rw-r--r-- | clang/lib/Basic/SourceManager.cpp | 33 |
1 files changed, 27 insertions, 6 deletions
diff --git a/clang/lib/Basic/SourceManager.cpp b/clang/lib/Basic/SourceManager.cpp index 20b32da2fad..c27675f38bc 100644 --- a/clang/lib/Basic/SourceManager.cpp +++ b/clang/lib/Basic/SourceManager.cpp @@ -413,8 +413,6 @@ FileID SourceManager::createFileID(const ContentCache *File, = SLocEntry::get(Offset, FileInfo::get(IncludePos, File, FileCharacter)); SLocEntryLoaded[PreallocatedID] = true; FileID FID = FileID::get(PreallocatedID); - if (File->FirstFID.isInvalid()) - File->FirstFID = 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 // almost guaranteed to be from that file. FileID FID = FileID::get(SLocEntryTable.size()-1); - if (File->FirstFID.isInvalid()) - File->FirstFID = FID; return LastFileIDLookup = FID; } @@ -1007,8 +1003,33 @@ SourceLocation SourceManager::getLocation(const FileEntry *SourceFile, if (i < Col-1) return SourceLocation(); - return getLocForStartOfFile(Content->FirstFID). - getFileLocWithOffset(FilePos + Col - 1); + // Find the first file ID that corresponds to the given file. + 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. |