FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Reserve extra space before elements when unshifting by headius · Pull Request #9059 · jruby/jruby · GitHub

/ jruby Public

Reserve extra space before elements when unshifting - #9059

Merged
headius merged 1 commit into
jruby:masterfrom
headius:unshift_optz
Nov 10, 2025
Merged

Reserve extra space before elements when unshifting#9059
headius merged 1 commit into
jruby:masterfrom
headius:unshift_optz

Conversation

headius commented Nov 4, 2025

Copy link
Copy Markdown
Member

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

headius added this to the JRuby 10.0.3.0 milestone Nov 4, 2025
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
headius merged commit d1af288 into jruby:master Nov 10, 2025
75 checks passed
headius deleted the unshift_optz branch November 10, 2025 22:51
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement efficient unshifting

1 participant


Back | FazBrowse Home | New Git URL