Skip to content

Commit 0739d91

Browse files
author
Pietro Vertechi
authored
Merge pull request #76 from piever/pv/nogen
Use normal functions for getindex
2 parents a5b24b6 + 4f858e4 commit 0739d91

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

src/structarray.jl

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,15 +116,20 @@ Base.size(s::StructArray{<:Any, <:Any, <:EmptyTup}) = (0,)
116116
Base.axes(s::StructArray) = axes(fieldarrays(s)[1])
117117
Base.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
126125
end
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+
128133
function Base.view(s::StructArray{T, N, C}, I...) where {T, N, C}
129134
StructArray{T}(map(v -> view(v, I...), fieldarrays(s)))
130135
end

0 commit comments

Comments
 (0)