[Lexer] Speedup LexTokenInternal

Only reset "NeedsCleaning" flag in case of re-entrant call.
Do not needlessly blank IdentifierInfo. This information will be set
once the token type is picked.

This yields a nice 1% speedup when pre-processing sqlite amalgamation
through:

valgrind --tool=callgrind ./bin/clang -E sqlite3.c -o/dev/null

Differential Revision: https://reviews.llvm.org/D137960
This commit is contained in:
serge-sans-paille 2022-11-09 23:13:51 +01:00
parent 462e461666
commit cb3f8d53e6
No known key found for this signature in database
GPG Key ID: 7B24DA8C9551659F
2 changed files with 9 additions and 4 deletions

View File

@ -175,6 +175,8 @@ public:
Loc = SourceLocation().getRawEncoding();
}
bool hasPtrData() const { return PtrData != nullptr; }
IdentifierInfo *getIdentifierInfo() const {
assert(isNot(tok::raw_identifier) &&
"getIdentifierInfo() on a tok::raw_identifier token!");

View File

@ -3516,10 +3516,9 @@ bool Lexer::Lex(Token &Result) {
/// token, not a normal token, as such, it is an internal interface. It assumes
/// that the Flags of result have been cleared before calling this.
bool Lexer::LexTokenInternal(Token &Result, bool TokAtPhysicalStartOfLine) {
LexNextToken:
// New token, can't need cleaning yet.
Result.clearFlag(Token::NeedsCleaning);
Result.setIdentifierInfo(nullptr);
LexStart:
assert(!Result.needsCleaning() && "Result doesn't need cleaning");
assert(!Result.hasPtrData() && "Result has been reset");
// CurPtr - Cache BufferPtr in an automatic variable.
const char *CurPtr = BufferPtr;
@ -4301,6 +4300,10 @@ HandleDirective:
// We parsed the directive; lex a token with the new state.
return false;
LexNextToken:
Result.clearFlag(Token::NeedsCleaning);
goto LexStart;
}
const char *Lexer::convertDependencyDirectiveToken(