@@ -68,14 +68,17 @@ Base.size(A::OffsetArray, d) = size(parent(A), d)
68
68
# performance-critical and relies on axes, these are usually worth
69
69
# optimizing thoroughly.
70
70
@inline Base. axes (A:: OffsetArray , d) =
71
- 1 <= d <= length (A. offsets) ? Base . Slice (axes (parent (A))[d] .+ A. offsets[d]) : (1 : 1 )
71
+ 1 <= d <= length (A. offsets) ? _slice (axes (parent (A))[d], A. offsets[d]) : (1 : 1 )
72
72
@inline Base. axes (A:: OffsetArray ) =
73
73
_axes (axes (parent (A)), A. offsets) # would rather use ntuple, but see #15276
74
74
@inline _axes (inds, offsets) =
75
- (Base . Slice (inds[1 ] .+ offsets[1 ]), _axes (tail (inds), tail (offsets))... )
75
+ (_slice (inds[1 ], offsets[1 ]), _axes (tail (inds), tail (offsets))... )
76
76
_axes (:: Tuple{} , :: Tuple{} ) = ()
77
77
Base. axes1 (A:: OffsetArray{T,0} ) where {T} = 1 : 1 # we only need to specialize this one
78
78
79
+ # Avoid the kw-arg on the range(r+x, length=length(r)) call in r .+ x
80
+ @inline _slice (r, x) = Base. Slice (Base. _range (first (r) + x, nothing , nothing , length (r)))
81
+
79
82
const OffsetAxis = Union{Integer, UnitRange, Base. Slice{<: UnitRange }, Base. OneTo}
80
83
function Base. similar (A:: OffsetArray , :: Type{T} , dims:: Dims ) where T
81
84
B = similar (parent (A), T, dims)
0 commit comments