aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2009-12-02 05:34:39 +0000
committerDouglas Gregor <dgregor@apple.com>2009-12-02 05:34:39 +0000
commit4a160e16eb97bee03e36962d11aedc6452710bc5 (patch)
tree9e099de79c2d0eed07b6ee21c7f5c41cba6a63c9
parent2f841ba3b3fd6babe751667470735651907b4001 (diff)
Eliminate the unnecessary FirstFID cache variable from the source manager's ContentCache
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@90294 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/clang/Basic/SourceManager.h5
-rw-r--r--lib/Basic/SourceManager.cpp33
2 files changed, 27 insertions, 11 deletions
diff --git a/include/clang/Basic/SourceManager.h b/include/clang/Basic/SourceManager.h
index 67b3d50064..6cf92e674b 100644
--- a/include/clang/Basic/SourceManager.h
+++ b/include/clang/Basic/SourceManager.h
@@ -72,11 +72,6 @@ namespace SrcMgr {
/// if SourceLineCache is non-null.
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
/// there is an error opening this buffer the first time, this returns null
/// and fills in the ErrorStr with a reason.
diff --git a/lib/Basic/SourceManager.cpp b/lib/Basic/SourceManager.cpp
index 20b32da2fa..c27675f38b 100644
--- a/lib/Basic/SourceManager.cpp
+++ b/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.