Author: Kugan Vivekanandarajah Date: 2023-02-21T16:25:46Z New Revision: d604c57164ecdb3084c8d00f9575158fddc30f81
URL: https://github.com/llvm/llvm-project/commit/d604c57164ecdb3084c8d00f9575158fddc30f81 DIFF: https://github.com/llvm/llvm-project/commit/d604c57164ecdb3084c8d00f9575158fddc30f81.diff LOG: [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 Added: Modified: clang/lib/AST/ASTContext.cpp Removed: ################################################################################ diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp index 9b0d7b2b4b5a5..d852ac52ce8cf 100644 --- a/clang/lib/AST/ASTContext.cpp +++ b/clang/lib/AST/ASTContext.cpp @@ -349,7 +349,7 @@ RawComment *ASTContext::getRawCommentForDeclNoCacheImpl( // There should be no other declarations or preprocessor directives between // comment and declaration. - if (Text.find_first_of(";{}#@") != StringRef::npos) + if (Text.find_last_of(";{}#@") != StringRef::npos) return nullptr; return CommentBeforeDecl; _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits