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

Add Arena::with_capacity #84

Closed
slivering opened this issue Aug 18, 2022 · 1 comment · Fixed by #85
Closed

Add Arena::with_capacity #84

slivering opened this issue Aug 18, 2022 · 1 comment · Fixed by #85

Comments

@slivering
Copy link
Contributor

When creating large trees, inserting many nodes causes the underlying Vec to reallocate frequently.
Arena::with_capacity would simply create allocate the Vec beforehand.

fn with_capacity(capacity: usize) -> Self {
    Self {
        nodes: Vec::with_capacity(capacity),
        first_free_slot: None,
        last_free_slot: None,
    }
}

I would also suggest adding the Arena::clear function which simply clears the Vec, causing all the created NodeIds to be invalid.
This is equivalent to removing all the Nodes while retaining the Vec capacity.
Unless I forgot something, I'm rather confident that such an implementation would not cause soundness issues, e.g. with the iterators.

@saschagrunert
Copy link
Owner

@slivering this sounds like a reasonable enhancement, do you plan to bring up a PR for that?

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 a pull request may close this issue.

2 participants