@@ -5,7 +5,7 @@ module Sort
55import .. @__MODULE__ , .. parentmodule
66const Base = parentmodule (@__MODULE__ )
77using . Base. Order
8- using . Base: copymutable, LinearIndices, length, (:), iterate, elsize,
8+ using . Base: copymutable, LinearIndices, length, (:), iterate, elsize, checkbounds,
99 eachindex, axes, first, last, similar, zip, OrdinalRange, firstindex, lastindex,
1010 AbstractVector, @inbounds , AbstractRange, @eval , @inline , Vector, @noinline ,
1111 AbstractMatrix, AbstractUnitRange, isless, identity, eltype, > , < , <= , >= , | , + , - , * , ! ,
@@ -605,7 +605,7 @@ function sort!(v::AbstractVector{T}, lo::Integer, hi::Integer, a::MergeSortAlg,
605605 hi- lo <= SMALL_THRESHOLD && return sort! (v, lo, hi, SMALL_ALGORITHM, o)
606606
607607 m = midpoint (lo, hi)
608- t = workspace (v, t0, m- lo+ 1 )
608+ t = workspace (v, t0, Base . OneTo ( m- lo+ 1 ) )
609609
610610 sort! (v, lo, m, a, o, t)
611611 sort! (v, m+ 1 , hi, a, o, t)
@@ -683,7 +683,7 @@ function radix_sort!(v::AbstractVector{U}, lo::Integer, hi::Integer, bits::Unsig
683683 t:: AbstractVector{U} , chunk_size= radix_chunk_size_heuristic (lo, hi, bits)) where U <: Unsigned
684684 # bits is unsigned for performance reasons.
685685 mask = UInt (1 ) << chunk_size - 1
686- counts = Vector {UInt } (undef, mask+ 2 )
686+ counts = Vector {Int } (undef, mask+ 2 )
687687
688688 @inbounds for shift in 0 : chunk_size: bits- 1
689689
@@ -746,9 +746,9 @@ function sort!(v::AbstractVector{B}, lo::Integer, hi::Integer, a::AdaptiveSort,
746746 v
747747end
748748
749- workspace (v:: AbstractVector , :: Nothing , len :: Integer ) = similar (v, len )
750- function workspace (v:: AbstractVector{T} , t:: AbstractVector{T} , len :: Integer ) where T
751- length (t) < len ? resize! (t, len) : t
749+ workspace (v:: AbstractVector , :: Nothing , indices :: AbstractUnitRange = eachindex (v)) = similar (v, indices )
750+ function workspace (v:: AbstractVector{T} , t:: AbstractVector{T} , indices :: AbstractUnitRange = eachindex (v) ) where T
751+ checkbounds (Bool, t, indices) ? t : similar (t, indices)
752752end
753753maybe_unsigned (x:: Integer ) = x # this is necessary to avoid calling unsigned on BigInt
754754maybe_unsigned (x:: BitSigned ) = unsigned (x)
@@ -856,7 +856,7 @@ function sort!(v::AbstractVector{T}, lo::Integer, hi::Integer, a::AdaptiveSort,
856856 u[i] -= u_min
857857 end
858858
859- u2 = radix_sort! (u, lo, hi, bits, reinterpret (U, workspace (v, t, hi )))
859+ u2 = radix_sort! (u, lo, hi, bits, reinterpret (U, workspace (v, t)))
860860 uint_unmap! (v, u2, lo, hi, o, u_min)
861861end
862862
0 commit comments