perf: collapse OfType chains in JUnitXmlWriter (#6052) by thomhurst · Pull Request #6070 · thomhurst/TUnit (original) (raw)

Code Review

No issues found. This is a clean, correct micro-optimization.

What the PR does

Collapses three independent LINQ chains into a single loop in and , eliminating up to 3 iterator allocations and up to 3 full traversals of per test node.

Correctness analysis

The only structural risk in this pattern is the chain: on a single loop iteration, at most one variable can be assigned. In theory, if a property object were simultaneously a subtype of two target types (e.g., both a and a ), the old three-pass code would assign it to both variables while the new code would only assign it to the first matching branch.

That risk is fully mitigated here:

The early-break optimization is also correct: it only fires once all three (or two, in ) variables are assigned, which requires they were all found — no premature exit possible.

Summary

Behavior is semantically identical to the original, the change is safe, and the performance improvement is real. LGTM.