================
@@ -548,7 +548,15 @@ TranslationUnitDecl *Decl::getTranslationUnitDecl() {
}
ASTContext &Decl::getASTContext() const {
- return getTranslationUnitDecl()->getASTContext();
+ if (const auto *TUD = dyn_cast<TranslationUnitDecl>(this))
+ return TUD->getASTContext();
----------------
nico wrote:
I could! But checking `this`'s type is very cheap, and then we don't have to
`getDeclContext()` for TranslationUnitDecls. Looking up things globally is
presumably common and it's nice for this to be fast.
But to be honest, I haven't measured how just
```
ASTContext &Decl::getASTContext() const {
if (!DC->CachedASTContext)
DC->CachedASTContext = &getTranslationUnitDecl()->getASTContext();
return *DC->CachedASTContext;
}
```
would do. I should probably measure it. I'll do so and report back.
https://github.com/llvm/llvm-project/pull/226612
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits