[clang] [Clang] Fix quadratic designated-initializer checking (PR #225573)
Oliver Hunt via cfe-commits
cfe-commits at lists.llvm.org
Tue Sep 22 23:16:12 PDT 2026
================
----------------
ojhunt wrote:
I feel like I've seen index searches before, so there should probably be a method on ASTContext - something like `std::optional<unsigned> getFieldIndex(const RecordDecl*, const FieldDecl*)` and then we get
```cpp
if (auto SelfIndex = Context.getFieldIndex(RD, KnownField)) {
FieldIndex = *SelfIndex;
} else {
// A field of another record: its cached index isn't RD's numbering ....
}
```
I'd kind of prefer both branches abstracted behind getFieldIndex, but I'm unsure if the direct subobject field is useful (or even expected) in other cases? If we think that's reasonable/safe then essentially this entire if/else would end on in the getFieldIndex method.
https://github.com/llvm/llvm-project/pull/225573
More information about the cfe-commits
mailing list