summaryrefslogtreecommitdiffstats
path: root/clang/lib/Lex
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2009-01-21 07:43:11 +0000
committerChris Lattner <sabre@nondot.org>2009-01-21 07:43:11 +0000
commitad89ec013f5f9d99fc436723153f00123e9a8ebe (patch)
tree0d30271a46d8edb930a5d3e931b2829e6c0cba22 /clang/lib/Lex
parent66c6562e24f7fbaacd9f1e6531baed2b314376c2 (diff)
downloadbcm5719-llvm-ad89ec013f5f9d99fc436723153f00123e9a8ebe.tar.gz
bcm5719-llvm-ad89ec013f5f9d99fc436723153f00123e9a8ebe.zip
Add a bit to IdentifierInfo that acts as a simple predicate which
tells us whether Preprocessor::HandleIdentifier needs to be called. Because this method is only rarely needed, this saves a call and a bunch of random checks. This drops the time in HandleIdentifier from 3.52ms to .98ms on cocoa.h on my machine. llvm-svn: 62675
Diffstat (limited to 'clang/lib/Lex')
-rw-r--r--clang/lib/Lex/Lexer.cpp4
-rw-r--r--clang/lib/Lex/PTHLexer.cpp4
-rw-r--r--clang/lib/Lex/Preprocessor.cpp5
-rw-r--r--clang/lib/Lex/TokenLexer.cpp5
4 files changed, 14 insertions, 4 deletions
diff --git a/clang/lib/Lex/Lexer.cpp b/clang/lib/Lex/Lexer.cpp
index 19b3121c644..f7937d5d70f 100644
--- a/clang/lib/Lex/Lexer.cpp
+++ b/clang/lib/Lex/Lexer.cpp
@@ -560,7 +560,9 @@ FinishIdentifier:
// Finally, now that we know we have an identifier, pass this off to the
// preprocessor, which may macro expand it or something.
- return PP->HandleIdentifier(Result);
+ if (Result.getIdentifierInfo()->isHandleIdentifierCase())
+ PP->HandleIdentifier(Result);
+ return;
}
// Otherwise, $,\,? in identifier found. Enter slower path.
diff --git a/clang/lib/Lex/PTHLexer.cpp b/clang/lib/Lex/PTHLexer.cpp
index 81349171fe8..99bb3f795d8 100644
--- a/clang/lib/Lex/PTHLexer.cpp
+++ b/clang/lib/Lex/PTHLexer.cpp
@@ -143,7 +143,9 @@ LexNextToken:
if (TKind == tok::identifier) {
MIOpt.ReadToken();
- return PP->HandleIdentifier(Tok);
+ if (Tok.getIdentifierInfo()->isHandleIdentifierCase())
+ PP->HandleIdentifier(Tok);
+ return;
}
if (TKind == tok::eof) {
diff --git a/clang/lib/Lex/Preprocessor.cpp b/clang/lib/Lex/Preprocessor.cpp
index 5d9fc9567dc..e53c392c388 100644
--- a/clang/lib/Lex/Preprocessor.cpp
+++ b/clang/lib/Lex/Preprocessor.cpp
@@ -718,6 +718,11 @@ IdentifierInfo *Preprocessor::LookUpIdentifierInfo(Token &Identifier,
/// HandleIdentifier - This callback is invoked when the lexer reads an
/// identifier. This callback looks up the identifier in the map and/or
/// potentially macro expands it or turns it into a named token (like 'for').
+///
+/// Note that callers of this method are guarded by checking the
+/// IdentifierInfo's 'isHandleIdentifierCase' bit. If this method changes, the
+/// IdentifierInfo methods that compute these properties will need to change to
+/// match.
void Preprocessor::HandleIdentifier(Token &Identifier) {
assert(Identifier.getIdentifierInfo() &&
"Can't handle identifiers without identifier info!");
diff --git a/clang/lib/Lex/TokenLexer.cpp b/clang/lib/Lex/TokenLexer.cpp
index 82c4d926aee..c945843459f 100644
--- a/clang/lib/Lex/TokenLexer.cpp
+++ b/clang/lib/Lex/TokenLexer.cpp
@@ -326,8 +326,9 @@ void TokenLexer::Lex(Token &Tok) {
}
// Handle recursive expansion!
- if (Tok.getIdentifierInfo() && !DisableMacroExpansion)
- return PP.HandleIdentifier(Tok);
+ if (Tok.getIdentifierInfo() && !DisableMacroExpansion &&
+ Tok.getIdentifierInfo()->isHandleIdentifierCase())
+ PP.HandleIdentifier(Tok);
// Otherwise, return a normal token.
}
OpenPOWER on IntegriCloud