Don't allow scratch arrays used by mergeSort to grow unbounded.

Pre-allocate before sorting, and trim after.

Fixes #1719