[cfe-commits] r38752 - in /cfe/cfe/trunk: Basic/SourceManager.cpp include/clang/Basic/SourceManager.h
sabre at cs.uiuc.edu
sabre at cs.uiuc.edu
Wed Jul 11 09:24:20 PDT 2007
Author: sabre
Date: Wed Jul 11 11:24:19 2007
New Revision: 38752
URL: http://llvm.org/viewvc/llvm-project?rev=38752&view=rev
Log:
Add a single-entry cache for macro instantation locations. This significantly
reduces the number of FileID's made and tracked.
Modified:
cfe/cfe/trunk/Basic/SourceManager.cpp
cfe/cfe/trunk/include/clang/Basic/SourceManager.h
Modified: cfe/cfe/trunk/Basic/SourceManager.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Basic/SourceManager.cpp?rev=38752&r1=38751&r2=38752&view=diff
==============================================================================
--- cfe/cfe/trunk/Basic/SourceManager.cpp (original)
+++ cfe/cfe/trunk/Basic/SourceManager.cpp Wed Jul 11 11:24:19 2007
@@ -121,11 +121,24 @@
// Resolve InstantLoc down to a real logical location.
InstantLoc = getLogicalLoc(InstantLoc);
-
- // Add a FileID for this. FIXME: should cache these!
- FileIDs.push_back(FileIDInfo::getMacroExpansion(InstantLoc,
- PhysLoc.getFileID()));
- unsigned InstantiationFileID = FileIDs.size();
+
+ unsigned InstantiationFileID;
+ // If this is the same instantiation as was requested last time, return this
+ // immediately.
+ if (PhysLoc.getFileID() == LastInstantiationLoc_MacroFID &&
+ InstantLoc == LastInstantiationLoc_InstantLoc) {
+ InstantiationFileID = LastInstantiationLoc_Result;
+ } else {
+ // Add a FileID for this. FIXME: should cache these!
+ FileIDs.push_back(FileIDInfo::getMacroExpansion(InstantLoc,
+ PhysLoc.getFileID()));
+ InstantiationFileID = FileIDs.size();
+
+ // Remember this in the single-entry cache for next time.
+ LastInstantiationLoc_MacroFID = PhysLoc.getFileID();
+ LastInstantiationLoc_InstantLoc = InstantLoc;
+ LastInstantiationLoc_Result = InstantiationFileID;
+ }
return SourceLocation(InstantiationFileID, PhysLoc.getRawFilePos());
}
Modified: cfe/cfe/trunk/include/clang/Basic/SourceManager.h
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/include/clang/Basic/SourceManager.h?rev=38752&r1=38751&r2=38752&view=diff
==============================================================================
--- cfe/cfe/trunk/include/clang/Basic/SourceManager.h (original)
+++ cfe/cfe/trunk/include/clang/Basic/SourceManager.h Wed Jul 11 11:24:19 2007
@@ -165,7 +165,14 @@
/// FileIDs - Information about each FileID. FileID #0 is not valid, so all
/// entries are off by one.
std::vector<SrcMgr::FileIDInfo> FileIDs;
+
+ /// LastInstantiationLoc_* - Cache the last instantiation request for fast
+ /// lookup. Macros often want many tokens instantated at the same location.
+ SourceLocation LastInstantiationLoc_InstantLoc;
+ unsigned LastInstantiationLoc_MacroFID;
+ unsigned LastInstantiationLoc_Result;
public:
+ SourceManager() { LastInstantiationLoc_MacroFID = ~0U; }
~SourceManager();
/// createFileID - Create a new FileID that represents the specified file
More information about the cfe-commits
mailing list