Skip to content
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

Remove appends in Map and Repeat #2

Merged
merged 1 commit into from
Nov 12, 2022

Conversation

matthewsanetra
Copy link
Collaborator

Previously, in Map and Repeat, new slices were being allocated with an initial length of 0, which was incremented by an append every iteration. These functions return a slice of the same size as their input slice, and so there should be no need to append at all.

This PR sets the final length of the slice in the make call, and then directly indexes the slice in the loop. I've noticed there is much less generated assembly.

@thecsw thecsw self-requested a review November 12, 2022 06:23
Copy link
Owner

@thecsw thecsw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good notice, I thought they would perform the same, I was just used to append. Approved. Thanks

@thecsw thecsw merged commit 3d49c15 into thecsw:master Nov 12, 2022
@matthewsanetra matthewsanetra deleted the redundant_appends branch November 12, 2022 13:43
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.

2 participants