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.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@62675 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Basic/IdentifierTable.cpp b/lib/Basic/IdentifierTable.cpp
index d7ef915..304c7a9 100644
--- a/lib/Basic/IdentifierTable.cpp
+++ b/lib/Basic/IdentifierTable.cpp
@@ -32,6 +32,7 @@
IsExtension = false;
IsPoisoned = false;
IsCPPOperatorKeyword = false;
+ NeedsHandleIdentifier = false;
FETokenInfo = 0;
Entry = 0;
}
diff --git a/lib/Lex/Lexer.cpp b/lib/Lex/Lexer.cpp
index 19b3121..f7937d5 100644
--- a/lib/Lex/Lexer.cpp
+++ b/lib/Lex/Lexer.cpp
@@ -560,7 +560,9 @@
// 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/lib/Lex/PTHLexer.cpp b/lib/Lex/PTHLexer.cpp
index 8134917..99bb3f7 100644
--- a/lib/Lex/PTHLexer.cpp
+++ b/lib/Lex/PTHLexer.cpp
@@ -143,7 +143,9 @@
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/lib/Lex/Preprocessor.cpp b/lib/Lex/Preprocessor.cpp
index 5d9fc95..e53c392 100644
--- a/lib/Lex/Preprocessor.cpp
+++ b/lib/Lex/Preprocessor.cpp
@@ -718,6 +718,11 @@
/// 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/lib/Lex/TokenLexer.cpp b/lib/Lex/TokenLexer.cpp
index 82c4d92..c945843 100644
--- a/lib/Lex/TokenLexer.cpp
+++ b/lib/Lex/TokenLexer.cpp
@@ -326,8 +326,9 @@
}
// 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.
}