[clang] [Clang][Lexer][Performance] Optimize Lexer whitespace skipping logic (PR #180819)
Nikolas Klauser via cfe-commits
cfe-commits at lists.llvm.org
Sun Feb 15 23:13:46 PST 2026
philnik777 wrote:
> > We should also check whether a loop that simply checks for all whitespaces is faster. All the non-' ' whitespaces are consecutive numbers together, so it boils down to a `(c >= '\t' && c <= '\r') || c == ' '` (though `\n` has special handling, so it might not be as perfect).
>
> `isHorizontalWhitespace` only matches `' '`, `'\t'`, `'\f'`, `'\v'`. I tried replacing the conditions with
>
> ```c++
> *CurPtr == ' ' || *CurPtr == '\t' || *CurPtr == '\f' || *CurPtr == '\v'
> ```
>
> but it is slower, which is understandable seeing [what it optimizes to](https://godbolt.org/z/P6coT8nn5).
If you look three lines below your first change you can see that there is a `isVerticalWhitespace` call, which checks for the remaining whitespaces.
https://github.com/llvm/llvm-project/pull/180819
More information about the cfe-commits
mailing list