diff --git a/base/array.jl b/base/array.jl index 218f765fac929..7655ba1530eb9 100644 --- a/base/array.jl +++ b/base/array.jl @@ -677,10 +677,8 @@ function grow_to!(dest, itr, st) end ## Iteration ## -function iterate(A::Array, i=1) - @_propagate_inbounds_meta - i >= length(A) + 1 ? nothing : (A[i], i+1) -end + +iterate(A::Array, i=1) = (@_inline_meta; (i % UInt) - 1 < length(A) ? (@inbounds A[i], i + 1) : nothing) ## Indexing: getindex ## diff --git a/base/iterators.jl b/base/iterators.jl index 3595bc9028920..49b0aecb90886 100644 --- a/base/iterators.jl +++ b/base/iterators.jl @@ -946,10 +946,9 @@ function length(itr::PartitionIterator) end function iterate(itr::PartitionIterator{<:Vector}, state=1) - iterate(itr.c, state) === nothing && return nothing - l = state - r = min(state + itr.n-1, length(itr.c)) - return view(itr.c, l:r), r + 1 + state > length(itr.c) && return nothing + r = min(state + itr.n - 1, length(itr.c)) + return view(itr.c, state:r), r + 1 end struct IterationCutShort; end diff --git a/test/strings/basic.jl b/test/strings/basic.jl index dc6bb960401c7..c43aa06869273 100644 --- a/test/strings/basic.jl +++ b/test/strings/basic.jl @@ -555,7 +555,8 @@ mutable struct CharStr <: AbstractString chars::Vector{Char} CharStr(x) = new(collect(x)) end -Base.iterate(x::CharStr, i::Integer=1) = iterate(x.chars, i) +Base.iterate(x::CharStr) = iterate(x.chars) +Base.iterate(x::CharStr, i::Int) = iterate(x.chars, i) Base.lastindex(x::CharStr) = lastindex(x.chars) @testset "cmp without UTF-8 indexing" begin # Simple case, with just ANSI Latin 1 characters