This change expands the array for an unshift by sliding elements
forward, leaving additional space for future unshifts to proceed
without copying or reallocating. When expanding, the existing
elements are moved to the end of the native array.
This assumes that if one value is unshifted, future values are also
likely to be unshifted rather than pushed at the end. This could
reduce performance if values are being both unshifted (at begin)
and pushed (at end), but the trade-off to have the more common case
of all unshifts seems worth it.
Fixes jruby#9058
This change expands the array for an unshift by sliding elements forward, leaving additional space for future unshifts to proceed without copying or reallocating. When expanding, the existing elements are moved to the end of the native array.
This assumes that if one value is unshifted, future values are also likely to be unshifted rather than pushed at the end. This could reduce performance if values are being both unshifted (at begin) and pushed (at end), but the trade-off to have the more common case of all unshifts seems worth it.
Fixes #9058