@@ -109,27 +109,22 @@ function grow_to_structarray!(dest::AbstractArray, itr, elem = iterate(itr))
109109 return dest
110110end
111111
112- widenstructarray (dest:: AbstractArray , i, el:: S ) where {S} = widenstructarray (dest, i, S)
113-
114- function widenstructarray (dest:: StructArray{T} , i, :: Type{S} ) where {T, S}
115- sch = staticschema (S)
116- names = fieldnames (sch)
117- types = ntuple (i -> fieldtype (sch, i), fieldcount (sch))
118- cols = fieldarrays (dest)
119- if names == propertynames (cols)
120- nt = map ((a, b) -> widenstructarray (a, i, b), cols, strip_params (sch)(types))
121- ST = _promote_typejoin (S, T)
122- return StructArray {ST} (nt)
123- else
124- return widenarray (dest, i, S)
125- end
112+ widenstructarray (dest:: AbstractArray{S} , i, el:: T ) where {S, T} = widenstructarray (dest, i, _promote_typejoin (S, T))
113+
114+ function widenstructarray (dest:: StructArray , i, :: Type{T} ) where {T}
115+ sch = hasfields (T) ? staticschema (T) : nothing
116+ sch != = nothing && fieldnames (sch) == propertynames (dest) || return widenarray (dest, i, T)
117+ types = ntuple (x -> fieldtype (sch, x), fieldcount (sch))
118+ cols = Tuple (fieldarrays (dest))
119+ newcols = map ((a, b) -> widenstructarray (a, i, b), cols, types)
120+ return StructArray {T} (newcols)
126121end
127122
128- widenstructarray (dest:: AbstractArray , i, :: Type{S } ) where {S } = widenarray (dest, i, S )
123+ widenstructarray (dest:: AbstractArray , i, :: Type{T } ) where {T } = widenarray (dest, i, T )
129124
130- widenarray (dest:: AbstractArray{S } , i, :: Type{S } ) where {S } = dest
131- function widenarray (dest:: AbstractArray{S} , i, :: Type{T} ) where {S, T}
132- new = similar (dest, Base . promote_typejoin (S, T) , length (dest))
125+ widenarray (dest:: AbstractArray{T } , i, :: Type{T } ) where {T } = dest
126+ function widenarray (dest:: AbstractArray , i, :: Type{T} ) where T
127+ new = similar (dest, T , length (dest))
133128 copyto! (new, 1 , dest, 1 , i- 1 )
134129 new
135130end
0 commit comments