Skip to content

Commit 3318c34

Browse files
Lilith HafnerLilith Hafner
authored andcommitted
Remove redundant reverse_view! thanks @petvana
1 parent 3db4a31 commit 3318c34

File tree

1 file changed

+5
-13
lines changed

1 file changed

+5
-13
lines changed

base/sort.jl

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import ..@__MODULE__, ..parentmodule
66
const Base = parentmodule(@__MODULE__)
77
using .Base.Order
88
using .Base: length, first, last, axes, eltype, similar, iterate, keytype, copymutable,
9-
fill, eachindex, zip, copyto!, resize!, LinearIndices, require_one_based_indexing,
10-
AbstractVector, Vector, AbstractRange, OrdinalRange, UnitRange,
9+
fill, eachindex, zip, copyto!, reverse!, resize!, require_one_based_indexing,
10+
AbstractVector, Vector, AbstractRange, OrdinalRange, UnitRange, LinearIndices,
1111
identity, isless, min, max, extrema, sub_with_overflow, add_with_overflow, oneunit,
1212
reinterpret, signed, unsigned, Signed, Unsigned, typemin, Type, BitSigned,
1313
Missing, missing, ismissing, @eval, @inbounds, @inline, @noinline,
@@ -592,14 +592,6 @@ function partition!(t::AbstractVector, lo::Integer, hi::Integer, o::Ordering, v:
592592
pivot, lo-trues
593593
end
594594

595-
# Needed for bootstrapping because `view` is not available.
596-
function reverse_view!(v, lo, hi)
597-
for i in 0:div(hi-lo-1, 2)
598-
@inbounds v[lo+i], v[hi-i] = v[hi-i], v[lo+i]
599-
end
600-
v
601-
end
602-
603595
function sort!(v::AbstractVector, lo::Integer, hi::Integer, a::PartialQuickSort, o::Ordering, t::AbstractVector=similar(v), swap=false, rev=false)
604596
while lo < hi && hi - lo > SMALL_THRESHOLD
605597
pivot, j = swap ? partition!(v, lo, hi, o, t, rev) : partition!(t, lo, hi, o, v, rev)
@@ -609,12 +601,12 @@ function sort!(v::AbstractVector, lo::Integer, hi::Integer, a::PartialQuickSort,
609601
# For QuickSort, a.lo === a.hi === missing, so the first two branches get skipped
610602
if !ismissing(a.lo) && j <= a.lo # Skip sorting the lower part
611603
swap && copyto!(v, lo, t, lo, j-lo)
612-
rev && reverse_view!(v, lo, j-1)
604+
rev && reverse!(v, lo, j-1)
613605
lo = j+1
614606
rev = !rev
615607
elseif !ismissing(a.hi) && a.hi <= j # Skip sorting the upper part
616608
swap && copyto!(v, j+1, t, j+1, hi-j)
617-
rev || reverse_view!(v, j+1, hi)
609+
rev || reverse!(v, j+1, hi)
618610
hi = j-1
619611
elseif j-lo < hi-j
620612
# Sort the lower part recursively because it is smaller. Recursing on the
@@ -629,7 +621,7 @@ function sort!(v::AbstractVector, lo::Integer, hi::Integer, a::PartialQuickSort,
629621
end
630622
hi < lo && return v
631623
swap && copyto!(v, lo, t, lo, hi-lo+1)
632-
rev && reverse_view!(v, lo, hi)
624+
rev && reverse!(v, lo, hi)
633625
sort!(v, lo, hi, SMALL_ALGORITHM, o)
634626
end
635627

0 commit comments

Comments
 (0)