@@ -116,15 +116,20 @@ Base.size(s::StructArray{<:Any, <:Any, <:EmptyTup}) = (0,)
116116Base. axes (s:: StructArray ) = axes (fieldarrays (s)[1 ])
117117Base. axes (s:: StructArray{<:Any, <:Any, <:EmptyTup} ) = (1 : 0 ,)
118118
119- Base. @propagate_inbounds @generated function Base. getindex (x:: StructArray{T, N, C} , I:: Int... ) where {T, N, C}
120- args = [:(getfield (cols, $ i)[I... ]) for i in 1 : fieldcount (C)]
121- return quote
122- cols = fieldarrays (x)
123- @boundscheck checkbounds (x, I... )
124- @inbounds $ (Expr (:call , :createinstance , :T , args... ))
119+ get_ith (cols:: NamedTuple , I... ) = get_ith (Tuple (cols), I... )
120+ function get_ith (cols:: NTuple{N, Any} , I... ) where N
121+ ntuple (N) do i
122+ @inbounds res = getfield (cols, i)[I... ]
123+ return res
125124 end
126125end
127126
127+ Base. @propagate_inbounds function Base. getindex (x:: StructArray{T, N, C} , I:: Int... ) where {T, N, C}
128+ cols = fieldarrays (x)
129+ @boundscheck checkbounds (x, I... )
130+ return createinstance (T, get_ith (cols, I... )... )
131+ end
132+
128133function Base. view (s:: StructArray{T, N, C} , I... ) where {T, N, C}
129134 StructArray {T} (map (v -> view (v, I... ), fieldarrays (s)))
130135end
0 commit comments