@@ -54,7 +54,7 @@ function _collect_structarray(itr, elem, len; initializer = default_initializer)
54
54
el, st = elem
55
55
S = typeof (el)
56
56
dest = initializer (S, (len,))
57
- dest[1 ] = el
57
+ @inbounds dest[1 ] = el
58
58
return _collect_structarray! (dest, itr, st, Base. IteratorSize (itr))
59
59
end
60
60
@@ -78,7 +78,7 @@ function collect_to_structarray!(dest::AbstractArray, itr, offs, st)
78
78
@inbounds dest[i] = el
79
79
i += 1
80
80
else
81
- new = widenstructarray (dest, i, el)
81
+ new = widen (dest, i, el)
82
82
@inbounds new[i] = el
83
83
return collect_to_structarray! (new, itr, i+ 1 , st)
84
84
end
@@ -97,29 +97,30 @@ function grow_to_structarray!(dest::AbstractArray, itr, elem = iterate(itr))
97
97
elem = iterate (itr, st)
98
98
i += 1
99
99
else
100
- new = widenstructarray (dest, i, el)
100
+ new = widen (dest, i, el)
101
101
push! (new, el)
102
102
return grow_to_structarray! (new, itr, iterate (itr, st))
103
103
end
104
104
end
105
105
return dest
106
106
end
107
107
108
- widenstructarray (dest:: AbstractArray{S} , i, el:: T ) where {S, T} = widenstructarray (dest, i, _promote_typejoin (S, T))
108
+ # Widen `dest` to contain `el` and copy until index `i-1`
109
+ widen (dest:: AbstractArray{S} , i, el:: T ) where {S, T} = _widenstructarray (dest, i, _promote_typejoin (S, T))
109
110
110
- function widenstructarray (dest:: StructArray , i, :: Type{T} ) where {T}
111
+ function _widenstructarray (dest:: StructArray , i, :: Type{T} ) where {T}
111
112
sch = hasfields (T) ? staticschema (T) : nothing
112
- sch != = nothing && fieldnames (sch) == propertynames (dest) || return widenarray (dest, i, T)
113
+ sch != = nothing && fieldnames (sch) == propertynames (dest) || return _widenarray (dest, i, T)
113
114
types = ntuple (x -> fieldtype (sch, x), fieldcount (sch))
114
115
cols = Tuple (fieldarrays (dest))
115
- newcols = map ((a, b) -> widenstructarray (a, i, b), cols, types)
116
+ newcols = map ((a, b) -> _widenstructarray (a, i, b), cols, types)
116
117
return StructArray {T} (newcols)
117
118
end
118
119
119
- widenstructarray (dest:: AbstractArray , i, :: Type{T} ) where {T} = widenarray (dest, i, T)
120
+ _widenstructarray (dest:: AbstractArray , i, :: Type{T} ) where {T} = _widenarray (dest, i, T)
120
121
121
- widenarray (dest:: AbstractArray{T} , i, :: Type{T} ) where {T} = dest
122
- function widenarray (dest:: AbstractArray , i, :: Type{T} ) where T
122
+ _widenarray (dest:: AbstractArray{T} , i, :: Type{T} ) where {T} = dest
123
+ function _widenarray (dest:: AbstractArray , i, :: Type{T} ) where T
123
124
new = similar (dest, T, length (dest))
124
125
copyto! (new, 1 , dest, 1 , i- 1 )
125
126
new
@@ -148,7 +149,7 @@ function _append!!(dest::AbstractVector, itr, ::Union{Base.HasShape, Base.HasLen
148
149
fr === nothing && return dest
149
150
el, st = fr
150
151
i = lastindex (dest) + 1
151
- new = iscompatible (el, dest) ? dest : widenstructarray (dest, i, el)
152
+ new = iscompatible (el, dest) ? dest : widen (dest, i, el)
152
153
resize! (new, length (dest) + n)
153
154
@inbounds new[i] = el
154
155
return collect_to_structarray! (new, itr, i + 1 , st)
0 commit comments