@@ -84,12 +84,6 @@ Base.to_indices(x::ComponentArray, i::Tuple{Vararg{Union{Integer, CartesianIndex
8484Base. to_indices (x:: ComponentArray , i:: Tuple{Vararg{Int64}} ) where N = i
8585Base. to_index (x:: ComponentArray , i) = i
8686
87- # Get AbstractAxis index
88- @inline Base. getindex (:: AbstractAxis , idx:: FlatIdx ) = ComponentIndex (idx)
89- @inline Base. getindex (ax:: AbstractAxis , :: Colon ) = ComponentIndex (:, ax)
90- @inline Base. getindex (:: AbstractAxis{IdxMap} , s:: Symbol ) where IdxMap =
91- ComponentIndex (getproperty (IdxMap, s))
92-
9387# Get ComponentArray index
9488Base. @propagate_inbounds Base. getindex (x:: ComponentArray , idx:: CartesianIndex ) = getdata (x)[idx]
9589Base. @propagate_inbounds Base. getindex (x:: ComponentArray , idx:: FlatIdx... ) = getdata (x)[idx... ]
10195Base. @propagate_inbounds Base. getindex (x:: ComponentArray , :: Colon ) = getdata (x)[:]
10296Base. @propagate_inbounds Base. getindex (x:: ComponentArray , :: Colon... ) = x
10397@inline Base. getindex (x:: ComponentArray , idx... ) = getindex (x, toval .(idx)... )
104- @inline Base. getindex (x:: ComponentArray , idx:: Val... ) = _getindex (x, idx... )
98+ @inline Base. getindex (x:: ComponentArray , idx:: Val... ) = _getindex (getindex, x, idx... )
10599
106100# Set ComponentArray index
107101Base. @propagate_inbounds Base. setindex! (x:: ComponentArray , v, idx:: FlatOrColonIdx... ) = setindex! (getdata (x), v, idx... )
@@ -111,22 +105,23 @@ Base.@propagate_inbounds Base.setindex!(x::ComponentArray, v, ::Colon) = setinde
111105
112106# Explicitly view
113107Base. @propagate_inbounds Base. view (x:: ComponentArray , idx:: ComponentArrays.FlatIdx... ) = view (getdata (x), idx... )
114- Base. @propagate_inbounds Base. view (x:: ComponentArray , idx... ) = _getindex (x, toval .(idx)... )
108+ Base. @propagate_inbounds Base. view (x:: ComponentArray , idx... ) = _getindex (view, x, toval .(idx)... )
109+
110+ Base. @propagate_inbounds Base. maybeview (x:: ComponentArray , idx:: ComponentArrays.FlatIdx... ) = Base. maybeview (getdata (x), idx... )
111+ Base. @propagate_inbounds Base. maybeview (x:: ComponentArray , idx... ) = _getindex (Base. maybeview, x, toval .(idx)... )
115112
116113# Generated get and set index methods to do all of the heavy lifting in the type domain
117- @generated function _getindex (x:: ComponentArray , idx... )
114+ @generated function _getindex (index_fun, x:: ComponentArray , idx... )
118115 ci = getindex .(getaxes (x), getval .(idx))
119116 inds = map (i -> i. idx, ci)
120117 axs = map (i -> i. ax, ci)
121118 axs = remove_nulls (axs... )
122- # the index must be valid after computing `ci`
123- :(Base. @_inline_meta ; ComponentArray (Base. maybeview (getdata (x), $ inds... ), $ axs... ))
119+ return :(Base. @_inline_meta ; ComponentArray (index_fun (getdata (x), $ inds... ), $ axs... ))
124120end
125121
126122@generated function _setindex! (x:: ComponentArray , v, idx... )
127123 ci = getindex .(getaxes (x), getval .(idx))
128124 inds = map (i -> i. idx, ci)
129- # the index must be valid after computing `ci`
130125 return :(Base. @_inline_meta ; setindex! (getdata (x), v, $ inds... ))
131126end
132127
0 commit comments