[cfe-commits] r38691 - /cfe/cfe/trunk/Lex/Lexer.cpp

sabre at cs.uiuc.edu sabre at cs.uiuc.edu
Wed Jul 11 09:23:51 PDT 2007


Author: sabre
Date: Wed Jul 11 11:23:51 2007
New Revision: 38691

URL: http://llvm.org/viewvc/llvm-project?rev=38691&view=rev
Log:
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.

Modified:
    cfe/cfe/trunk/Lex/Lexer.cpp

Modified: cfe/cfe/trunk/Lex/Lexer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Lex/Lexer.cpp?rev=38691&r1=38690&r2=38691&view=diff

==============================================================================
--- cfe/cfe/trunk/Lex/Lexer.cpp (original)
+++ cfe/cfe/trunk/Lex/Lexer.cpp Wed Jul 11 11:23:51 2007
@@ -928,6 +928,15 @@
   // 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.





More information about the cfe-commits mailing list