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

length_count: use Vec::with_capacity #1462

Closed

Conversation

tanriol
Copy link

@tanriol tanriol commented Nov 13, 2021

This change avoids reallocation while filling in the array. In my case this causes a ~20% perf increase.

This might cause regressions if some users rely on nom not allocating the whole array before an error happens, causing their parsers to change behavior from "starts parsing, encounters an error, backtracks to a previous alt/opt/whatever" to "starts parsing, causes an OOM abort". I don't think nom provides any guarantees in either direction.

This change avoids reallocation while filling in the array. In my case
this causes a ~20% perf increase.
@Geal Geal added this to the 8.0 milestone Mar 14, 2022
@Geal
Copy link
Collaborator

Geal commented May 5, 2024

I will close this now, length_count will use with_capacity in nom 8, with an additional check for an initial max capacity to make sure the allocation is reasonable:

https://github.com/rust-bakery/nom/blame/main/src/multi/mod.rs#L1546-L1551

@Geal Geal closed this May 5, 2024
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