[clang] 9628cb1 - [NFC] Use higher level constructs to check for whitespace/newlines in the lexer
via cfe-commits
cfe-commits at lists.llvm.org
Mon Mar 15 10:27:32 PDT 2021
Author: serge-sans-paille
Date: 2021-03-15T18:27:19+01:00
New Revision: 9628cb1feef63d764c57fd0652016f9188000e2f
URL: https://github.com/llvm/llvm-project/commit/9628cb1feef63d764c57fd0652016f9188000e2f
DIFF: https://github.com/llvm/llvm-project/commit/9628cb1feef63d764c57fd0652016f9188000e2f.diff
LOG: [NFC] Use higher level constructs to check for whitespace/newlines in the lexer
It turns out that according to valgrind and perf, it's also slightly faster.
Differential Revision: https://reviews.llvm.org/D98637
Added:
Modified:
clang/lib/Lex/Lexer.cpp
Removed:
################################################################################
diff --git a/clang/lib/Lex/Lexer.cpp b/clang/lib/Lex/Lexer.cpp
index e63574e306fb..75c0fb65f5b1 100644
--- a/clang/lib/Lex/Lexer.cpp
+++ b/clang/lib/Lex/Lexer.cpp
@@ -2061,7 +2061,7 @@ bool Lexer::LexAngledStringLiteral(Token &Result, const char *CurPtr) {
if (C == '\\')
C = getAndAdvanceChar(CurPtr, Result);
- if (C == '\n' || C == '\r' || // Newline.
+ if (isVerticalWhitespace(C) || // Newline.
(C == 0 && (CurPtr - 1 == BufferEnd))) { // End of file.
// If the filename is unterminated, then it must just be a lone <
// character. Return this as such.
@@ -3208,10 +3208,10 @@ bool Lexer::LexTokenInternal(Token &Result, bool TokAtPhysicalStartOfLine) {
const char *CurPtr = BufferPtr;
// Small amounts of horizontal whitespace is very common between tokens.
- if ((*CurPtr == ' ') || (*CurPtr == '\t')) {
- ++CurPtr;
- while ((*CurPtr == ' ') || (*CurPtr == '\t'))
+ if (isHorizontalWhitespace(*CurPtr)) {
+ do {
++CurPtr;
+ } while (isHorizontalWhitespace(*CurPtr));
// If we are keeping whitespace and other tokens, just return what we just
// skipped. The next lexer invocation will return the token after the
More information about the cfe-commits
mailing list