Skip to content

Fix unnecessary allocations in prepend! for small vectors by checking… #58839

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

YuvaanshKapila
Copy link

… capacity before shifting

Imported Base._capacity and Base._set_length! to inspect and modify vector capacity and length.

Modified _prepend! to conditionally avoid allocations by shifting elements in-place when possible.

Preserved original behavior for iterators without known length.

Added safety checks for one-based indexing.

Improved overall performance and allocation behavior for prepend!.

… capacity before shifting

Imported Base._capacity and Base._set_length! to inspect and modify vector capacity and length.

Modified _prepend! to conditionally avoid allocations by shifting elements in-place when possible.

Preserved original behavior for iterators without known length.

Added safety checks for one-based indexing.

Improved overall performance and allocation behavior for prepend!.
@StefanKarpinski
Copy link
Member

Did you use AI?

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.

3 participants