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

Replace usage of push_all and resize with extend #25

Merged
merged 1 commit into from
Apr 12, 2015

Conversation

skade
Copy link
Contributor

@skade skade commented Apr 4, 2015

This allows removal of the collections feature gate.

Builds and tests on beta-1.0.0.

Please note that extend is slower then push_all currently: rust-lang/rust#24028 (comment), but the error message says that extend will probably be the future way to go.

This allows removal of the collections feature gate
//let mut v = Vec::with_capacity(self.size);
//self.v.clear();
self.v.resize(self.size, 0);
self.v.extend(repeat(0).take(self.size - len));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm making the assumption here that resize only every grows the vector. I might be mistaken there - I only glanced at the surroundings.

If I'm mistaken, I'll add the "grow or shrink?"-dance.

Copy link
Collaborator

Choose a reason for hiding this comment

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

yes, it can only grow the vector

@Geal
Copy link
Collaborator

Geal commented Apr 4, 2015

I think it can work, but it may be a good idea to wait a bit for extend to get faster, or push_all to be reimplemented, what do you think?

@skade
Copy link
Contributor Author

skade commented Apr 4, 2015

Hm, I tried finding any substance to that claim of extend/iter being slower, and I didn't find any. Considering that push_all() also does all the clone work hidden away and will probably be a shim over extend anyways, I think this is a good way to go.

I ran your mp4 parser on bigbuck.mp4 and the beta version with this implementation is in the same range, even a bit faster in debug mode (??). Take it with a grain of salt, as I hacked around nom_benchmark a little, but given that extend is stable and ready now, I'd prefer that in this case.

In the end, I intend to use nom with a piece of software I'm developing on top of beta, so my agenda is clear there ;).

Geal added a commit that referenced this pull request Apr 12, 2015
Replace usage of push_all and resize with extend
@Geal Geal merged commit 0f14353 into rust-bakery:master Apr 12, 2015
@Geal
Copy link
Collaborator

Geal commented Apr 12, 2015

I think now it is a better idea to support beta. The performance hit will only affect producers and consumers, and there are other ways to optimize them.

Thank you for fixing this part of the code :)

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