[clangd] Avoid scanning up to end of file on each comment!
authorSam McCall <sam.mccall@gmail.com>
Wed, 5 Oct 2022 20:23:10 +0000 (22:23 +0200)
committerTobias Hieta <tobias@hieta.se>
Mon, 10 Oct 2022 06:49:11 +0000 (08:49 +0200)
commit73ea64f30411bcb9a2f32649a49d4c23780ee045
tree48f73ffe6e56adacb7a59a0fff6777a0b3f1cc8f
parent61fa70903191f2350dc20dee2c9f45a8fbdf28af
[clangd] Avoid scanning up to end of file on each comment!

Assigning char* (pointing at comment start) to StringRef was causing us
to scan the rest of the source file looking for the null terminator.

This seems to be eating about 8% of our *total* CPU!

While fixing this, factor out the common bits from the two places we're
parsing IWYU pragmas.

Differential Revision: https://reviews.llvm.org/D135314

(cherry picked from commit 5d2d527c32da2081b814ef8b446bc3e037f74b0a)
clang-tools-extra/clangd/Headers.cpp
clang-tools-extra/clangd/Headers.h
clang-tools-extra/clangd/index/CanonicalIncludes.cpp
clang-tools-extra/clangd/unittests/HeadersTests.cpp