Skip to content

Commit c44f9c7

Browse files
committed
These collections can't change size so don't waist time testing for it
1 parent 82341bf commit c44f9c7

File tree

1 file changed

+21
-24
lines changed

1 file changed

+21
-24
lines changed

src/indexing.jl

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -323,39 +323,27 @@ Reconstruct `A` given the values in `data`. New methods using `unsafe_reconstruc
323323
should only dispatch on `A`.
324324
"""
325325
function unsafe_reconstruct(A::OneTo, data; kwargs...)
326-
if can_change_size(A)
327-
return typeof(A)(data)
326+
if data isa Slice ||
327+
!(known_length(A) === nothing || known_length(A) !== known_length(data))
328+
return A
328329
else
329-
if data isa Slice ||
330-
!(known_length(A) === nothing || known_length(A) !== known_length(data))
331-
return A
332-
else
333-
return OneTo(data)
334-
end
330+
return OneTo(data)
335331
end
336332
end
337333
function unsafe_reconstruct(A::UnitRange, data; kwargs...)
338-
if can_change_size(A)
339-
return typeof(A)(data)
334+
if data isa Slice ||
335+
!(known_length(A) === nothing || known_length(A) !== known_length(data))
336+
return A
340337
else
341-
if data isa Slice ||
342-
!(known_length(A) === nothing || known_length(A) !== known_length(data))
343-
return A
344-
else
345-
return UnitRange(data)
346-
end
338+
return UnitRange(data)
347339
end
348340
end
349341
function unsafe_reconstruct(A::OptionallyStaticUnitRange, data; kwargs...)
350-
if can_change_size(A)
351-
return typeof(A)(data)
342+
if data isa Slice ||
343+
!(known_length(A) === nothing || known_length(A) !== known_length(data))
344+
return A
352345
else
353-
if data isa Slice ||
354-
!(known_length(A) === nothing || known_length(A) !== known_length(data))
355-
return A
356-
else
357-
return OptionallyStaticUnitRange(data)
358-
end
346+
return OptionallyStaticUnitRange(data)
359347
end
360348
end
361349
function unsafe_reconstruct(A::AbstractUnitRange, data; kwargs...)
@@ -420,6 +408,15 @@ previously executed `to_index(old_axis, arg) -> index`. `to_axis` assumes that
420408
return to_axis(IndexStyle(axis), axis, inds)
421409
end
422410
end
411+
412+
# don't need to check size b/c slice means it's the entire axis
413+
@inline function to_axis(axis, inds::Slice)
414+
if can_change_size(axis)
415+
return copy(axis)
416+
else
417+
return axis
418+
end
419+
end
423420
@inline function to_axis(S::IndexStyle, axis, inds)
424421
return unsafe_reconstruct(axis, StaticInt(1):static_length(inds))
425422
end

0 commit comments

Comments
 (0)