Closed
Description
For a vector of length n
, it currently allocates 2 * n
space, but for small vectors it only uses n
... and should be able get away without allocations completely.
Note: the comparison function could unwind, so this will need to be careful about what it puts on the stack etc. to be failure safe... although there is a test that should help ensure that. [].swap
is probably useful.
Random notes:
- servo saw speed-ups from this: style: Quicksort rules to avoid allocation of temporary vectors. servo/servo#1567 (apparently for vectors of length at most 16)
- there may be some advantage to switching what implementation is used based on the size of the elements, e.g. for
&mut [uint]
,[].swap
is cheap, but for&mut [HundredKBStruct]
, many swaps may be more expensive than what one can do with an allocation. (Pure speculation on my part.) Of course, we could just avoid doing this, and people could go faster by boxing it and storing~HundredKBStruct
.