diff options
author | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2010-07-12 18:49:30 +0000 |
---|---|---|
committer | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2010-07-12 18:49:30 +0000 |
commit | 03569eaabceb14a20e23d043135fdccbc7309a96 (patch) | |
tree | f606419347f942c53e6940a4ec9aab79550c080b /lib | |
parent | 1982c18522a4aefd57207bbd2d66d93945c41f92 (diff) |
If we are past tok::eof and in caching lex mode, avoid caching repeated tok::eofs.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@108175 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Lex/PPCaching.cpp | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/lib/Lex/PPCaching.cpp b/lib/Lex/PPCaching.cpp index 20e3b3dd9d..16fcaa365c 100644 --- a/lib/Lex/PPCaching.cpp +++ b/lib/Lex/PPCaching.cpp @@ -45,13 +45,19 @@ void Preprocessor::Backtrack() { } void Preprocessor::CachingLex(Token &Result) { + if (!InCachingLexMode()) + return; + if (CachedLexPos < CachedTokens.size()) { Result = CachedTokens[CachedLexPos++]; return; } ExitCachingLexMode(); - Lex(Result); + // True if we consumed everything already. + bool PastEOF = CurPPLexer == 0 && CurTokenLexer == 0; + if (!PastEOF) + Lex(Result); if (!isBacktrackEnabled()) { // All cached tokens were consumed. @@ -60,10 +66,12 @@ void Preprocessor::CachingLex(Token &Result) { return; } - // Cache the lexed token. + // Cache the lexed token if it's not a repeated tok::eof. EnterCachingLexMode(); - CachedTokens.push_back(Result); - ++CachedLexPos; + if (!PastEOF) { + CachedTokens.push_back(Result); + ++CachedLexPos; + } } void Preprocessor::EnterCachingLexMode() { |