This is a follow-up to r62675:
Refactor how the preprocessor changes a token from being an tok::identifier to a
keyword (e.g. tok::kw_for). Instead of doing this in HandleIdentifier, hoist this
common case out into the caller, so that every keyword doesn't have to go through
HandleIdentifier. This drops time in HandleIdentifier from 1.25ms to .62ms, and
speeds up clang -Eonly with PTH by about 1%.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@62855 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Lex/Lexer.cpp b/lib/Lex/Lexer.cpp
index fca8fd4..3174a05 100644
--- a/lib/Lex/Lexer.cpp
+++ b/lib/Lex/Lexer.cpp
@@ -558,6 +558,10 @@
// identifier table.
IdentifierInfo *II = PP->LookUpIdentifierInfo(Result, IdStart);
+ // Change the kind of this identifier to the appropriate token kind, e.g.
+ // turning "for" into a keyword.
+ Result.setKind(II->getTokenID());
+
// Finally, now that we know we have an identifier, pass this off to the
// preprocessor, which may macro expand it or something.
if (II->isHandleIdentifierCase())
diff --git a/lib/Lex/PTHLexer.cpp b/lib/Lex/PTHLexer.cpp
index b0f0627..ec76a29 100644
--- a/lib/Lex/PTHLexer.cpp
+++ b/lib/Lex/PTHLexer.cpp
@@ -101,7 +101,13 @@
if (IdentifierID) {
MIOpt.ReadToken();
IdentifierInfo *II = PTHMgr.GetIdentifierInfo(IdentifierID-1);
+
Tok.setIdentifierInfo(II);
+
+ // Change the kind of this identifier to the appropriate token kind, e.g.
+ // turning "for" into a keyword.
+ Tok.setKind(II->getTokenID());
+
if (II->isHandleIdentifierCase())
PP->HandleIdentifier(Tok);
return;
diff --git a/lib/Lex/Preprocessor.cpp b/lib/Lex/Preprocessor.cpp
index e53c392..d0a15e4 100644
--- a/lib/Lex/Preprocessor.cpp
+++ b/lib/Lex/Preprocessor.cpp
@@ -759,10 +759,6 @@
if (II.isCPlusPlusOperatorKeyword())
Identifier.setIdentifierInfo(0);
- // Change the kind of this identifier to the appropriate token kind, e.g.
- // turning "for" into a keyword.
- Identifier.setKind(II.getTokenID());
-
// If this is an extension token, diagnose its use.
// We avoid diagnosing tokens that originate from macro definitions.
if (II.isExtensionToken() && Features.C99 && !DisableMacroExpansion)
diff --git a/lib/Lex/TokenLexer.cpp b/lib/Lex/TokenLexer.cpp
index c945843..dd5352c 100644
--- a/lib/Lex/TokenLexer.cpp
+++ b/lib/Lex/TokenLexer.cpp
@@ -326,9 +326,14 @@
}
// Handle recursive expansion!
- if (Tok.getIdentifierInfo() && !DisableMacroExpansion &&
- Tok.getIdentifierInfo()->isHandleIdentifierCase())
- PP.HandleIdentifier(Tok);
+ if (IdentifierInfo *II = Tok.getIdentifierInfo()) {
+ // Change the kind of this identifier to the appropriate token kind, e.g.
+ // turning "for" into a keyword.
+ Tok.setKind(II->getTokenID());
+
+ if (!DisableMacroExpansion && II->isHandleIdentifierCase())
+ PP.HandleIdentifier(Tok);
+ }
// Otherwise, return a normal token.
}