]> granicus.if.org Git - clang/commitdiff
Only resolve a macro's instantiation loc once per macro, instead of once
authorChris Lattner <sabre@nondot.org>
Mon, 26 Jan 2009 03:46:22 +0000 (03:46 +0000)
committerChris Lattner <sabre@nondot.org>
Mon, 26 Jan 2009 03:46:22 +0000 (03:46 +0000)
per token lexed from it.  This speeds up clang on c99-intconst-1.c from
the GCC testsuite from 3.64s to 2.66s (36%).  This reduces the number of
binary search FileID lookups from 251570522 to 114175649 on this testcase.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@62992 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Lex/TokenLexer.cpp

index ea4ce669d1d93de144ec46698cc7016456ea53f5..3707ef1ed6f02b590193bc84bfc0e03766806247 100644 (file)
@@ -31,7 +31,14 @@ void TokenLexer::Init(Token &Tok, MacroArgs *Actuals) {
   Macro = PP.getMacroInfo(Tok.getIdentifierInfo());
   ActualArgs = Actuals;
   CurToken = 0;
+  
   InstantiateLoc = Tok.getLocation();
+
+  // If the instantiation loc is not already a FileID, resolve it here.  If we
+  // don't do this, we end up doing it once per token lexed.
+  if (!InstantiateLoc.isFileID())
+    InstantiateLoc = PP.getSourceManager().getInstantiationLoc(InstantiateLoc);
+  
   AtStartOfLine = Tok.isAtStartOfLine();
   HasLeadingSpace = Tok.hasLeadingSpace();
   Tokens = &*Macro->tokens_begin();