@@ -433,10 +433,28 @@ find_extended_inds(::ScalarIndex, I...) = (@inline; find_extended_inds(I...))
433
433
find_extended_inds (i1, I... ) = (@inline ; (i1, find_extended_inds (I... )... ))
434
434
find_extended_inds () = ()
435
435
436
- function iterate (V:: FastContiguousSubArray ,
437
- state = (V. offset1+ firstindex (V), V. offset1+ lastindex (V)))
436
+ function isvalid_index (p, i, l)
437
+ if firstindex (p) == 1
438
+ (i- 1 )% UInt < l% UInt <= lastindex (p)% UInt
439
+ else
440
+ firstindex (p) <= i <= l <= lastindex (p)
441
+ end
442
+ end
443
+
444
+ function Base. iterate (v:: Base.FastContiguousSubArray ,
445
+ state = v. offset1 .+ (firstindex (v), lastindex (v)))
446
+ p = parent (v)
447
+ i, l = state
448
+ isvalid_index (p, i, l) ? (@inbounds p[i], (i+ 1 , l)) : nothing
449
+ end
450
+
451
+ stride1 (v:: SubArray{T,N,P} ) where {T,N,P} = P <: StridedArray ? stride (v, 1 ) : v. stride1
452
+
453
+ function Base. iterate (v:: Base.FastSubArray ,
454
+ state = v. offset1 .+ stride1 (v) .* (firstindex (v), lastindex (v)))
455
+ p = parent (v)
438
456
i, l = state
439
- @inbounds i - 1 < l ? (V . parent [i], (i+ 1 , l)) : nothing
457
+ isvalid_index (p, i, l) ? (@inbounds p [i], (i+ stride1 (v) , l)) : nothing
440
458
end
441
459
442
460
function unsafe_convert (:: Type{Ptr{T}} , V:: SubArray{T,N,P,<:Tuple{Vararg{RangeIndex}}} ) where {T,N,P}
0 commit comments