Skip to content

Commit

Permalink
Use applicable correctly in sort! (JuliaLang#46194)
Browse files Browse the repository at this point in the history
(also replace hi-lo+1 with len)
  • Loading branch information
LilithHafner authored and pcjentsch committed Aug 18, 2022
1 parent c669dc1 commit ecd6d66
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions base/sort.jl
Original file line number Diff line number Diff line change
Expand Up @@ -863,14 +863,15 @@ function sort!(v::AbstractVector{T}, lo::Integer, hi::Integer, a::AdaptiveSort,
u[i] -= u_min
end

len = lenm1 + 1
if t !== nothing && checkbounds(Bool, t, lo:hi) # Fully preallocated and aligned buffer
u2 = radix_sort!(u, lo, hi, bits, reinterpret(U, t))
uint_unmap!(v, u2, lo, hi, o, u_min)
elseif t !== nothing && (applicable(resize!, t) || length(t) >= hi-lo+1) # Viable buffer
length(t) >= hi-lo+1 || resize!(t, hi-lo+1)
elseif t !== nothing && (applicable(resize!, t, len) || length(t) >= len) # Viable buffer
length(t) >= len || resize!(t, len)
t1 = axes(t, 1) isa OneTo ? t : view(t, firstindex(t):lastindex(t))
u2 = radix_sort!(view(u, lo:hi), 1, hi-lo+1, bits, reinterpret(U, t1))
uint_unmap!(view(v, lo:hi), u2, 1, hi-lo+1, o, u_min)
u2 = radix_sort!(view(u, lo:hi), 1, len, bits, reinterpret(U, t1))
uint_unmap!(view(v, lo:hi), u2, 1, len, o, u_min)
else # No viable buffer
u2 = radix_sort!(u, lo, hi, bits, similar(u))
uint_unmap!(v, u2, lo, hi, o, u_min)
Expand Down

0 comments on commit ecd6d66

Please sign in to comment.