@@ -25,27 +25,24 @@ struct StructArray{T, N, C<:Tup, I} <: AbstractArray{T, N}
2525    end 
2626end 
2727
28- #  common  type used  for indexing
28+ #  compute optimal  type to use  for indexing as a function of component types 
2929index_type (:: Type{NamedTuple{names, types}} ) where  {names, types} =  index_type (types)
3030index_type (:: Type{Tuple{}} ) =  Int
3131function  index_type (:: Type{T} ) where  {T<: Tuple }
3232    S, U =  tuple_type_head (T), tuple_type_tail (T)
33-     IndexStyle (S)  isa  IndexCartesian  ?  CartesianIndex{ ndims (S)}  :   index_type ( U)
33+     return   _index_type (S,  U)
3434end 
3535#  Julia v1.7.0-beta3 doesn't seem to specialize `index_type` as defined above
3636#  for tuple types with "many" elements (three or four, depending on the concrete
3737#  types). However, we can help the compiler for homogeneous types by defining
3838#  the specialization below.
39- function  index_type (:: Type{<:NTuple{N, S}} ) where  {N, S}
40-     if  IndexStyle (S) isa  IndexCartesian
41-         return  CartesianIndex{ndims (S)}
42-     else 
43-         return  Int
44-     end 
45- end 
46- 
39+ index_type (:: Type{NTuple{N, S}} ) where  {N, S} =  _index_type (S)
4740index_type (:: Type{StructArray{T, N, C, I}} ) where  {T, N, C, I} =  I
4841
42+ function  _index_type (:: Type{S} , :: Type{U} = Tuple{}) where  {S, U}
43+     return  IndexStyle (S) isa  IndexCartesian ?  CartesianIndex{ndims (S)} :  index_type (U)
44+ end 
45+ 
4946array_types (:: Type{StructArray{T, N, C, I}} ) where  {T, N, C, I} =  array_types (C)
5047array_types (:: Type{NamedTuple{names, types}} ) where  {names, types} =  types
5148array_types (:: Type{TT} ) where  {TT<: Tuple } =  TT
0 commit comments