From bf57c4d1163e6c4a9113f6163ce1da17f66e6cd5 Mon Sep 17 00:00:00 2001 From: Neven Sajko Date: Sat, 12 Apr 2025 10:10:58 +0200 Subject: [PATCH] iterators: merge duplicate `iterate` methods for `Reverse` The method bodies and state optional argument definition are exactly the same. The only difference between the two methods, is that the more specific method, for `Reverse{<:AbstractArray}`, had a `@propagate_inbounds` annotation. I simply deleted the more specific method, together with the annotation. Deleting the annotation is consistent with the fact that the `iterate(::AbstractArray)` method, in abstractarray.jl, has no such annotation. --- base/iterators.jl | 8 -------- 1 file changed, 8 deletions(-) diff --git a/base/iterators.jl b/base/iterators.jl index c7450781c4928..c7b12b76aa255 100644 --- a/base/iterators.jl +++ b/base/iterators.jl @@ -120,14 +120,6 @@ IteratorSize(::Type{Reverse{T}}) where {T} = IteratorSize(T) IteratorEltype(::Type{Reverse{T}}) where {T} = IteratorEltype(T) last(r::Reverse) = first(r.itr) # the first shall be last -# reverse-order array iterators: assumes more-specialized Reverse for eachindex -@propagate_inbounds function iterate(A::Reverse{<:AbstractArray}, state=(reverse(eachindex(A.itr)),)) - y = iterate(state...) - y === nothing && return y - idx, itrs = y - (A.itr[idx], (state[1], itrs)) -end - # Fallback method of `iterate(::Reverse{T})` which assumes the collection has `getindex(::T) and `reverse(eachindex(::T))` # don't propagate inbounds for this just in case function iterate(A::Reverse, state=(reverse(eachindex(A.itr)),))