[clang] [Clang] Cache AST context lookup for declarations (NFC) (PR #223047)

Mehdi Amini via cfe-commits cfe-commits at lists.llvm.org
Tue Sep 22 04:11:07 PDT 2026


================
@@ -1488,6 +1484,18 @@ DeclContext *DeclContext::getNonTransparentContext() {
   return DC;
 }
 
+ASTContext &DeclContext::getParentASTContextSlow() const {
+  const DeclContext *DC = this;
+  while (!DC->isTranslationUnit()) {
----------------
joker-eph wrote:

Implemented this by storing the owning ASTContext directly in DeclContext at construction, getParentASTContext() is now a direct return, removing both the null check and translation-unit walk. 

https://github.com/llvm/llvm-project/compare/99a9b8e86fdf154cee802677541c5a562cc3b36f..0edeaebf6ac4e095599c6e10adacdc933b4de068


https://github.com/llvm/llvm-project/pull/223047


More information about the cfe-commits mailing list