Skip to content

Commit

Permalink
fix #8347
Browse files Browse the repository at this point in the history
  • Loading branch information
vtjnash committed Nov 16, 2014
1 parent 970d83e commit 4547cb7
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions base/sort.jl
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,16 @@ function sort!(v::AbstractVector, lo::Int, hi::Int, a::QuickSortAlg, o::Ordering
v[i], v[j] = v[j], v[i]
end
v[j], v[lo] = v[lo], v[j]
lo < (j-1) && sort!(v, lo, j-1, a, o)
lo = j+1
if j-lo < hi-j
# recurse on the smaller chunk
# this is necessary to preserve O(log(n))
# stack space in the worst case (rather than O(n))
lo < (j-1) && sort!(v, lo, j-1, a, o)
lo = j+1
else
j+1 < hi && sort!(v, j+1, hi, a, o)
hi = j-1
end
end
return v
end
Expand Down

3 comments on commit 4547cb7

@vtjnash
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tkelman
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, backported in efd5966

@StefanKarpinski
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sweet. Good fix, @vtjnash. cc @illerucis

Please sign in to comment.