Skip to content

Use AtomicUsize unconditionally for inflight#30

Merged
ibraheemdev merged 1 commit intoibraheemdev:masterfrom
SabrinaJewson:inflight-usize
May 2, 2025
Merged

Use AtomicUsize unconditionally for inflight#30
ibraheemdev merged 1 commit intoibraheemdev:masterfrom
SabrinaJewson:inflight-usize

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