[clang] [AST] Iterate redecls starting from the canonical one in getRawCommentsForAnyRedecl() (PR #108475)
Younan Zhang via cfe-commits
cfe-commits at lists.llvm.org
Wed Sep 18 23:03:29 PDT 2024
================
@@ -440,14 +440,23 @@ const RawComment *ASTContext::getRawCommentForAnyRedecl(
// Any redeclarations of D that we haven't checked for comments yet?
// We can't use DenseMap::iterator directly since it'd get invalid.
- auto LastCheckedRedecl = [this, CanonicalD]() -> const Decl * {
- return CommentlessRedeclChains.lookup(CanonicalD);
- }();
+ const Decl *LastCheckedRedecl = CommentlessRedeclChains.lookup(CanonicalD);
+ bool CanUseCommentlessCache = false;
+ if (LastCheckedRedecl) {
+ for (auto *Redecl : CanonicalD->redecls()) {
+ if (Redecl == D) {
+ CanUseCommentlessCache = true;
+ break;
+ }
+ if (Redecl == LastCheckedRedecl)
+ break;
+ }
+ }
----------------
zyn0217 wrote:
Probably, we could move the logic to the lambda and just let the lambda return a nullptr when we're sure that `CanUseCommentlessCache` is false. This could save up the bool variable, WDYT?
(And you can also leave a FIXME here suggesting the algorithm could be improved in that `LastCheckedRedecl` would become useful again once we have traversed past the CanoncialDecl even if `CanUseCommentlessCache` is false.)
https://github.com/llvm/llvm-project/pull/108475
More information about the cfe-commits
mailing list