@@ -866,21 +866,24 @@ function _sort!(v::AbstractVector, a::RadixSort, o::DirectOrdering, kw)
866
866
U = UIntMappable (eltype (v), o)
867
867
# A large if-else chain to avoid type instabilities and dynamic dispatch
868
868
if scratch != = nothing && checkbounds (Bool, scratch, lo: hi) # Fully preallocated and aligned scratch
869
- if radix_sort! (u, lo, hi, bits, reinterpret (U, scratch))
869
+ t = reinterpret (U, scratch)
870
+ if radix_sort! (u, lo, hi, bits, t)
870
871
uint_unmap! (v, u, lo, hi, o, umn)
871
872
else
872
873
uint_unmap! (v, t, lo, hi, o, umn)
873
874
end
874
875
elseif scratch != = nothing && (applicable (resize!, scratch, len) || length (scratch) >= len) # Viable scratch
875
876
length (scratch) >= len || resize! (scratch, len)
876
877
t1 = axes (scratch, 1 ) isa OneTo ? scratch : view (scratch, firstindex (scratch): lastindex (scratch))
877
- if radix_sort! (view (u, lo: hi), 1 , len, bits, reinterpret (U, t1))
878
- uint_unmap! (view (v, lo: hi), u, 1 , len, o, umn)
878
+ t = reinterpret (U, t1)
879
+ if radix_sort! (view (u, lo: hi), 1 , len, bits, t)
880
+ uint_unmap! (view (v, lo: hi), view (u, lo: hi), 1 , len, o, umn)
879
881
else
880
882
uint_unmap! (view (v, lo: hi), t, 1 , len, o, umn)
881
883
end
882
884
else # No viable scratch
883
- if radix_sort! (u, lo, hi, bits, similar (u))
885
+ t = similar (u)
886
+ if radix_sort! (u, lo, hi, bits, t)
884
887
uint_unmap! (v, u, lo, hi, o, umn)
885
888
else
886
889
uint_unmap! (v, t, lo, hi, o, umn)
0 commit comments