Fix bug: const array size

We're using a constant array size here, which will create an incorrect
test since this will become part of the template instantiation and array
size is rarely (if ever) known at compilation time in a real
application.
Cleanup & tweaks
Fix broken case (malloc failure) and optimize.

This finally fixes the broken case when the element size is too large to
allocate a tmp buffer on the stack and malloc fails to allocate one on
the heap. In this case we do the same thing that msort does and defer to
the older and slower _quicksort() function. This is far better than
trying to accommodate a smaller tmp buffer on the heap because doing so
would bloat the common case dramatically.

This commit also contains number of optimizations and tweaks. In order
to safely (we presume) allocate a larger tmp buffer on the stack, we
reduce the size of the "stack" variable that the qsort on 64 bit
machines to support no more than 2^48 elements in an array. Now we'll
allocate up to 512 + def->align - 1 bytes on the stack for a tmp buffer,
before turning to the heap.