summaryrefslogtreecommitdiffstats
path: root/clang/Lex/MacroExpander.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2006-07-20 04:47:30 +0000
committerChris Lattner <sabre@nondot.org>2006-07-20 04:47:30 +0000
commit510ab61fd3c52c25cbc474f2c4f1c0e0312ef381 (patch)
tree365c73859ce747cd93d95981b3bf2497a13a9b99 /clang/Lex/MacroExpander.cpp
parent538d7f3c27cc6afe15cad65c3967318d74121666 (diff)
downloadbcm5719-llvm-510ab61fd3c52c25cbc474f2c4f1c0e0312ef381.tar.gz
bcm5719-llvm-510ab61fd3c52c25cbc474f2c4f1c0e0312ef381.zip
Add optimization for identifier##identifier -> identifier, the most common case of token pasting.
llvm-svn: 38747
Diffstat (limited to 'clang/Lex/MacroExpander.cpp')
-rw-r--r--clang/Lex/MacroExpander.cpp13
1 files changed, 11 insertions, 2 deletions
diff --git a/clang/Lex/MacroExpander.cpp b/clang/Lex/MacroExpander.cpp
index d65448759b6..a8e53258da3 100644
--- a/clang/Lex/MacroExpander.cpp
+++ b/clang/Lex/MacroExpander.cpp
@@ -455,9 +455,18 @@ void MacroExpander::PasteTokens(LexerToken &Tok) {
// and emit an error that it is unterminated.
if (Tok.getKind() == tok::slash && RHS.getKind() == tok::star) {
isInvalid = true;
+ } else if (Tok.getKind() == tok::identifier &&
+ Tok.getKind() == tok::identifier) {
+ // Common paste case: identifier+identifier = identifier. Avoid creating
+ // a lexer and other overhead.
+ PP.IncrementPasteCounter(true);
+ Result.StartToken();
+ Result.SetKind(tok::identifier);
+ Result.SetLocation(ResultTokLoc);
+ Result.SetLength(LHSLen+RHSLen);
} else {
- // FIXME: Handle common cases: ident+ident, ident+simplenumber here.
-
+ PP.IncrementPasteCounter(false);
+
// Make a lexer to lex this string from.
SourceManager &SourceMgr = PP.getSourceManager();
const char *ResultStrData = SourceMgr.getCharacterData(ResultTokLoc);
OpenPOWER on IntegriCloud