diff --git a/src/FixedSizeArray.jl b/src/FixedSizeArray.jl index 57e16a7..9b5f917 100644 --- a/src/FixedSizeArray.jl +++ b/src/FixedSizeArray.jl @@ -404,14 +404,9 @@ function Base.reshape(a::FixedSizeArray, size::(NTuple{N,Int} where {N})) new_fixed_size_array(parent(a), size) end -# `iterate`: the `AbstractArray` fallback doesn't perform well, so add our own methods +# `iterate`: the `AbstractArray` fallback doesn't perform well, so add our own methods (copied from `Base.Array`) -function Base.iterate(a::FixedSizeArray) - iterate(parent(a)) -end -function Base.iterate(a::FixedSizeArray, state) - iterate(parent(a), state) -end +Base.iterate(A::FixedSizeArray, i=1) = (@inline; (i - 1)%UInt < length(A)%UInt ? (@inbounds A[i], i + 1) : nothing) """ FixedSizeArrayDefault{T,N}(undef, size::NTuple{N,Int}) diff --git a/test/runtests.jl b/test/runtests.jl index 3c7ee87..8aba697 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -698,4 +698,14 @@ end @test farr isa Transpose @test parent(farr) isa FixedSizeArray end + + @testset "Constant-prop through iterate" begin + @test Base.return_types() do + m = FixedSizeArray{Int}(undef, 3) + m[1] = 1 + m[2] = 2 + m[3] = 3 + tuple(m...) + end[] == NTuple{3, Int} + end end