diff --git a/src/impl/utils.jl b/src/impl/utils.jl index 50af6e5..f4f94e2 100644 --- a/src/impl/utils.jl +++ b/src/impl/utils.jl @@ -65,6 +65,14 @@ end return fallback() end +@inline function terminating_foldlargs(op, fallback, x1, x2, x3) + acc = op(x1, x2) + acc isa Reduced && return unreduced(acc) + acc = op(acc, x3) + acc isa Reduced && return unreduced(acc) + return fallback() +end + struct Padded{T, N} value::T diff --git a/src/impl/vectors.jl b/src/impl/vectors.jl index bfecead..735dcc3 100644 --- a/src/impl/vectors.jl +++ b/src/impl/vectors.jl @@ -186,14 +186,19 @@ end # Base.checkbounds(::Type{Bool}, A::UnionVector, i) = # checkbounds(Bool, A.data, i) && checkbounds(Bool, A.typeid, i) -@inline function Base.setindex!(A::UnionVector, v, i::Int) +@inline function Base.setindex!(A::UnionVector, v::T, i::Int) where {T} + @noinline unreachable() = throw(ElTypeLookupFailed{nothing}()) @boundscheck checkbounds(A, i) typeid = A.typeid - view_and_id(A, typeof(v)) do xs, id + return terminating_foldlargs(unreachable, (v, 1), A.views...) do (v, id), xs Base.@_inline_meta - @inbounds typeid[i] = id - @inbounds xs[i] = v - nothing + if v isa paddedtype(eltype(xs)) + @inbounds typeid[i] = id + @inbounds xs[i] = v + Reduced(nothing) + else + (v, id + 1) + end end end