Add simple optimization: check for (and skip) spaces and tabs immediately

before lexing a token.  This speeds the common case where tokens are
separated by small amount of whitespace.  This makes a slight but
reproducible positive effect lexing a preprocessed carbon.h.

llvm-svn: 38691
This commit is contained in:
Chris Lattner 2006-07-10 06:34:27 +00:00
parent 03f83485bd
commit eb54b5973e
1 changed files with 9 additions and 0 deletions

View File

@ -928,6 +928,15 @@ LexNextToken:
// CurPtr - Cache BufferPtr in an automatic variable.
const char *CurPtr = BufferPtr;
// Small amounts of horizontal whitespace is very common between tokens.
if ((*CurPtr == ' ') || (*CurPtr == '\t')) {
++CurPtr;
while ((*CurPtr == ' ') || (*CurPtr == '\t'))
++CurPtr;
BufferPtr = CurPtr;
Result.SetFlag(LexerToken::LeadingSpace);
}
unsigned SizeTmp, SizeTmp2; // Temporaries for use in cases below.
// Read a character, advancing over it.