[NFC] Use find_last_of when seraching for code in getRawCommentForDeclNoCacheImpl
authorKugan Vivekanandarajah <kuganv@gmail.com>
Tue, 21 Feb 2023 16:24:26 +0000 (16:24 +0000)
committerIvan Murashko <ivan.murashko@gmail.com>
Tue, 21 Feb 2023 16:25:46 +0000 (16:25 +0000)
commitd604c57164ecdb3084c8d00f9575158fddc30f81
tree9cf279552940dfc78a64d97eeb2383cb463e36cf
parent1b634c0da3605f38495b0310d65f577c0bee8f6d
[NFC] Use find_last_of when seraching for code in getRawCommentForDeclNoCacheImpl

ASTContext::getRawCommentForDeclNoCacheImpl in this case, extracts the text between
the comment and declaration to make sure if there are  no other declarations or preprocessor
directives between  comment or declarations.

While using Text.find_first_of or Text.find_last_of  is functionally the same,
 using Text.find_last_of terminates fast in the presence of such.

Especially in generated code with sparse comments, it takes longer
to bailout when there is code in-between. Searching from last
(with find_last_of) bails out faster.

This shows up in perf profiles with clangd in some auto-generated code.
ASTContext::getRawCommentForDeclNoCacheImpl showing as much as 18.2% in this
case. With find_last_of, this drops to 2.8%.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D141950
clang/lib/AST/ASTContext.cpp