diff options
author | Ted Kremenek <kremenek@apple.com> | 2008-12-17 23:52:11 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2008-12-17 23:52:11 +0000 |
commit | 74c3e6e5e95af08096aab415d1ce15f15ffff02a (patch) | |
tree | af2084243b6ed9888429978d24c90fe3bca7ccc6 /lib/Lex/PTHLexer.cpp | |
parent | 99f06ba988922ea721035a89e6d3c66ba100ba8a (diff) |
Rewrite PTHLexer::DiscardToEndOfLine() to not use GetToken and instead only read the bytes needed to determine if a token is not at the start of the line.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@61172 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Lex/PTHLexer.cpp')
-rw-r--r-- | lib/Lex/PTHLexer.cpp | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/lib/Lex/PTHLexer.cpp b/lib/Lex/PTHLexer.cpp index 9a883b0172..c05b4b0010 100644 --- a/lib/Lex/PTHLexer.cpp +++ b/lib/Lex/PTHLexer.cpp @@ -131,15 +131,24 @@ void PTHLexer::DiscardToEndOfLine() { assert(ParsingPreprocessorDirective && ParsingFilename == false && "Must be in a preprocessing directive!"); - // Already at end-of-file? - if (AtLastToken()) - return; - - // Find the first token that is not the start of the *current* line. - Token T; - for (Lex(T); !AtLastToken(); Lex(T)) - if (GetToken().isAtStartOfLine()) - return; + // Skip tokens by only peeking at their token kind and the flags. + // We don't need to actually reconstruct full tokens from the token buffer. + // This saves some copies and it also reduces IdentifierInfo* lookup. + const char* p = CurPtr; + while (1) { + // Read the token kind. Are we at the end of the file? + tok::TokenKind x = (tok::TokenKind) (uint8_t) *p; + if (x == tok::eof) break; + + // Read the token flags. Are we at the start of the next line? + Token::TokenFlags y = (Token::TokenFlags) (uint8_t) p[1]; + if (y == Token::StartOfLine) break; + + // Skip to the next token. + p += DISK_TOKEN_SIZE; + } + + CurPtr = p; } //===----------------------------------------------------------------------===// |