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

libcollections: Fix RingBuf growth for non-power-of-two capacities #16314

Merged
merged 1 commit into from
Aug 9, 2014

Conversation

Ryman
Copy link
Contributor

@Ryman Ryman commented Aug 7, 2014

See test for details.

@brson
Copy link
Contributor

brson commented Aug 7, 2014

I don't see what the bug was. It was requesting to reserve a particular size, which means the vec will definitely reserve at least that much, so it looks like the worst that should have happened was that excess capacity was wasted. What was actually happening to cause a bug?

Extending the ringbuf to whatever capacity the vector decided to create seems like it could affect the ringbuf algorithm in subtle ways. Does the ringbuf care about growing in exact sizes of two?

@huonw
Copy link
Member

huonw commented Aug 7, 2014

Does the ringbuf care about growing in exact sizes of two?

If it guarantees that it is always a power of two, it can be more efficient by using shifts/bitmasking instead of divisions/remainders for computing the wrapped-around indexes (etc.).

@Ryman
Copy link
Contributor Author

Ryman commented Aug 7, 2014

@brson The RingBuf itself doesn't seem to care about power of two currently, but it was making assumptions about the growth of the underlying vector which lead to indexing being wrong.

E.g. grow requests a new length of 6 (3*2), it gets a capacity of 8 (vec grows by power of two) but does all its move calculations based on 6 which leaves gaps in the underlying vector so the lo counter doesn't wrap before it meets a None value, which then fails.

@brson
Copy link
Contributor

brson commented Aug 9, 2014

@huonw It doesn't seem to be doing that. I don't see any power-of-two assumptions in the code.

@lilyball
Copy link
Contributor

lilyball commented Aug 9, 2014

@brson The rest of the grow() function, that doesn't show up in the diff, uses newlen as if it were the capacity of the vector. If the vector reserved more space than was requested, this left a bunch of Nones at the end of the vector, after the elements that were supposed to be attached to the end.

@huonw
Copy link
Member

huonw commented Aug 9, 2014

@brson yes, it's not currently doing that, it was merely a related possible optimisation.

bors added a commit that referenced this pull request Aug 9, 2014
@bors bors closed this Aug 9, 2014
@bors bors merged commit 64896d6 into rust-lang:master Aug 9, 2014
bors added a commit to rust-lang-ci/rust that referenced this pull request Jan 21, 2024
…r=Veykril

`macro_rules` as macro name

This PR makes RA parse `macro_rules! {}` (note the missing identifier) as a `MACRO_CALL` instead of `MACRO_RULES`.

Fixes rust-lang#15969.
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.

5 participants