[clang] [Clang] Avoid quadratic pack-indexing instantiation (store only the selected element) (PR #213790)
Younan Zhang via cfe-commits
cfe-commits at lists.llvm.org
Tue Aug 4 19:54:39 PDT 2026
================
@@ -7167,6 +7173,43 @@ TreeTransform<Derived>::TransformPackIndexingType(TypeLocBuilder &TLB,
SubtitutedTypes.push_back(Pack);
continue;
}
+ // Fast path: substitute only the selected element instead of all N. A
+ // pack-indexing type inside a pack expansion (`T...[Is]...`) is transformed
+ // once per outer element, so substituting the whole pack each time is
+ // O(N^2) in time and memory.
+ if (!RetainExpansion && Types.size() == 1 && IndexExpr.isUsable() &&
+ !IndexExpr.get()->isInstantiationDependent()) {
----------------
zyn0217 wrote:
Why does it have to live inside the loop of `Types` if we are dealing with cases where there's only a Type?
https://github.com/llvm/llvm-project/pull/213790
More information about the cfe-commits
mailing list