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 Vec::reset for reusing previously allocated space #17

Merged
merged 1 commit into from
Nov 7, 2024

Conversation

l4l
Copy link
Contributor

@l4l l4l commented Oct 25, 2024

resolves #16

Copy link
Owner

@ibraheemdev ibraheemdev left a comment

Choose a reason for hiding this comment

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

This looks good overall, just a couple comments.

src/lib.rs Outdated Show resolved Hide resolved
src/raw.rs Outdated
let len = Location::bucket_capacity(i);
for i in 0..len {
let e = unsafe { &mut *e.add(i) };
e.active.store(false, Ordering::Relaxed);
Copy link
Owner

Choose a reason for hiding this comment

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

This will not drop the values. You can use the raw iterator and call next_owned instead.

Copy link
Contributor Author

@l4l l4l Oct 28, 2024

Choose a reason for hiding this comment

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

Not sure how to utilize iterator here, so just dropped the entry similarly to impl Drop for Entry.

Also covered that in the test, thanks for noticing.

tests/vec.rs Show resolved Hide resolved
@ibraheemdev
Copy link
Owner

Thanks!

@ibraheemdev ibraheemdev merged commit a640e09 into ibraheemdev:master Nov 7, 2024
6 checks passed
@ibraheemdev
Copy link
Owner

Released in 0.2.7.

@l4l l4l deleted the reusable-space branch November 8, 2024 23:18
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.

How to reuse once allocated space
2 participants