JuliaLang/julia — pull request #2932 by kmsquire (2013-04-25 08:04:55+00:00)
Title: Fix select!([1,2],1)

This came up on julia-user earlier today, and is a rather subtle. The minimal test case is
```julia
select!([1,2],1)
```
which fails because the pivot ends up being the first element, and one of the index variables can then become zero.

More generally, this bug occurs whenever the select range is the first two elements of an array. `Quicksort` gets around this by using `InsertionSort` for small arrays.

It's unclear to me how much overhead is introduced by the `sort2` call or if it is inlined, so feel free to make a better fix.