Right-size the array in getSampleArray().

This allows the JS engine to do a better job of allocating the right
number of elements for the array, avoiding some resizings. For the PDF
in #2504, this avoids 100s of MiBs of allocations in Firefox.
Merge pull request #5191 from nnethercote/getSampleArray-array-length

Right-size the array in getSampleArray().