[PATCH] D141950: Use find_last_of when seraching for code in getRawCommentForDeclNoCacheImpl

Kugan Vivekanandarajah via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Feb 2 08:30:17 PST 2023


kuganv created this revision.
Herald added a subscriber: kadircet.
Herald added a project: All.
kuganv updated this revision to Diff 489882.
kuganv edited the summary of this revision.
kuganv added a comment.
kuganv added subscribers: DmitryPolukhin, 0x1eaf, ivanmurashko.
kuganv updated this revision to Diff 494242.
kuganv added reviewers: craig.topper, jkorous, rnk, gribozavr.
kuganv published this revision for review.
Herald added subscribers: cfe-commits, ilya-biryukov.
Herald added a project: clang.

Updating the summary.


kuganv added a comment.

Rebasing the diff to latest main


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%.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D141950

Files:
  clang/lib/AST/ASTContext.cpp


Index: clang/lib/AST/ASTContext.cpp
===================================================================
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -348,7 +348,7 @@
 
   // 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;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D141950.494242.patch
Type: text/x-patch
Size: 463 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230202/472a771d/attachment.bin>


More information about the cfe-commits mailing list