Skip to content

Use AtomicUsize unconditionally for inflight #30

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

Merged
merged 1 commit into from
May 2, 2025

Conversation

SabrinaJewson
Copy link
Contributor

By reducing the number of buckets by one, we set MAX_INDEX to just under isize::MAX instead of just under usize::MAX. Since it’s extremely unlikely one will have more than isize::MAX elements anyway (and is only possible at all in pathological cases like Vec<()>), this should not be a real problem for anyone. This allows us to simplify the code, using fetch_add on all platforms, as now we can more easily check for overflows with the simple assumption that there won’t be isize::MAX concurrent threads pushing to the vector.

By reducing the number of buckets by one, we set `MAX_INDEX` to just
under `isize::MAX` instead of just under `usize::MAX`. Since it’s
extremely unlikely one will have more than `isize::MAX` elements anyway
(and is only possible at all in pathological cases like `Vec<()>`), this
should not be a real problem for anyone. This allows us to simplify the
code, using `fetch_add` on all platforms, as now we can more easily
check for overflows with the simple assumption that there won’t be
`isize::MAX` concurrent threads pushing to the vector.
@ibraheemdev
Copy link
Owner

Looks good, thanks!

@ibraheemdev ibraheemdev merged commit 0da4d05 into ibraheemdev:master May 2, 2025
@SabrinaJewson SabrinaJewson deleted the inflight-usize branch May 2, 2025 13:15
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