From 3880403e0816963e41f427e549e023a324e15cc3 Mon Sep 17 00:00:00 2001 From: Alexander Plavin Date: Fri, 23 Feb 2024 06:38:55 -0500 Subject: [PATCH] optimize get_ith (#286) Co-authored-by: Pietro Vertechi --- src/structarray.jl | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/structarray.jl b/src/structarray.jl index 64ff17a9..4cfacdcf 100644 --- a/src/structarray.jl +++ b/src/structarray.jl @@ -338,12 +338,7 @@ to map(c -> c[I...], Tuple(cols)) ``` """ -@inline get_ith(cols::NamedTuple, I...) = get_ith(Tuple(cols), I...) -@inline function get_ith(cols::Tuple, I...) - @inbounds r = first(cols)[I...] - return (r, get_ith(Base.tail(cols), I...)...) -end -@inline get_ith(::Tuple{}, I...) = () +@inline @generated get_ith(cols::Tup, I...) = :(Base.Cartesian.@ntuple $(fieldcount(cols)) i -> @inbounds cols[i][I...]) Base.@propagate_inbounds Base.getindex(x::StructArray, I...) = _getindex(x, to_indices(x, I)...)