From 6cc3e36cd7f952d31ed24be277db9f1efa34e839 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Fri, 27 Oct 2006 04:12:35 +0000 Subject: [PATCH] Speed up block comment skipping by 35%. llvm-svn: 39059 --- clang/Lex/Lexer.cpp | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/clang/Lex/Lexer.cpp b/clang/Lex/Lexer.cpp index eb2e1e3b24c1..c84335599278 100644 --- a/clang/Lex/Lexer.cpp +++ b/clang/Lex/Lexer.cpp @@ -789,11 +789,31 @@ bool Lexer::SkipBlockComment(LexerToken &Result, const char *CurPtr) { } while (1) { - // Skip over all non-interesting characters. + // Skip over all non-interesting characters until we find end of buffer or a + // (probably ending) '/' character. // TODO: Vectorize this. Note: memchr on Darwin is slower than this loop. + + if (CurPtr + 24 < BufferEnd) { + // While not aligned to a 16-byte boundary. + while (C != '/' && ((intptr_t)CurPtr & 0x0F) != 0) + C = *CurPtr++; + + if (C == '/') goto FoundSlash; + + while (CurPtr[0] != '/' && + CurPtr[1] != '/' && + CurPtr[2] != '/' && + CurPtr[3] != '/' && + CurPtr+4 < BufferEnd) { + CurPtr += 4; + } + C = *CurPtr++; + } + while (C != '/' && C != '\0') C = *CurPtr++; + FoundSlash: if (C == '/') { if (CurPtr[-2] == '*') // We found the final */. We're done! break;