From d9d2b679d0728ea7f539f38aaea38e26b8b08043 Mon Sep 17 00:00:00 2001 From: Argyrios Kyrtzidis Date: Sun, 21 Aug 2011 23:33:04 +0000 Subject: Boost the efficiency of SourceManager::getMacroArgExpandedLocation. Currently getMacroArgExpandedLocation is very inefficient and for the case of a location pointing at the main file it will end up checking almost all of the SLocEntries. Make it faster: -Use a map of macro argument chunks to their expanded source location. The map is for a single source file, it's stored in the file's ContentCache and lazily computed, like the source lines cache. -In SLocEntry's FileInfo add an 'unsigned NumCreatedFIDs' field that keeps track of the number of FileIDs (files and macros) that were created during preprocessing of that particular file SLocEntry. This is useful when computing the macro argument map in skipping included files while scanning for macro arg FileIDs that lexed from a specific source file. Due to padding, the new field does not increase the size of SLocEntry. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@138225 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Lex/PreprocessorLexer.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'lib/Lex/PreprocessorLexer.cpp') diff --git a/lib/Lex/PreprocessorLexer.cpp b/lib/Lex/PreprocessorLexer.cpp index 808a81bd5e..0da9ef5531 100644 --- a/lib/Lex/PreprocessorLexer.cpp +++ b/lib/Lex/PreprocessorLexer.cpp @@ -17,6 +17,14 @@ #include "clang/Basic/SourceManager.h" using namespace clang; +PreprocessorLexer::PreprocessorLexer(Preprocessor *pp, FileID fid) + : PP(pp), FID(fid), InitialNumSLocEntries(0), + ParsingPreprocessorDirective(false), + ParsingFilename(false), LexingRawMode(false) { + if (pp) + InitialNumSLocEntries = pp->getSourceManager().local_sloc_entry_size(); +} + /// LexIncludeFilename - After the preprocessor has parsed a #include, lex and /// (potentially) macro expand the filename. void PreprocessorLexer::LexIncludeFilename(Token &FilenameTok) { -- cgit v1.2.1