Use a closure instead of three chained iterators Fixes the perf regression from #123948 That PR had chained a third option to the iterator which apparently didn't optimize well