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

Use extend_from_slice instead of iterator extend #53

Merged
merged 2 commits into from
Oct 13, 2016

Conversation

fhartwig
Copy link
Contributor

Extending a Vec using extend_from_slice is much faster than extending from an iterator. This reduces the time needed for quoting a string by 40-65% (40% on 50-char strings, 65% on 1000-char strings) if the char contains no escape characters. Also, I think it looks nicer 😃

@fhartwig
Copy link
Contributor Author

Incidentally, replacing the s.iter().position(|&v| v == self.quote) in the same method by memchr(self.quote, s) reduces the runtime by an order of magnitude. I wasn't sure if you consider quoting performance to be worth the extra dependency, though. I'd be happy to make that change as well if you think it's worth it.

@BurntSushi
Copy link
Owner

@fhartwig This is good work, and I'd probably accept the PR, but this is undoubtedly a breaking change since this probably increases the minimum Rust version required to compile csv. I guess I'm not opposed to merging this and doing a semver incompatible bump, since extend_from_slice has been around since 1.6.

Incidentally, replacing the s.iter().position(|&v| v == self.quote) in the same method by memchr(self.quote, s) reduces the runtime by an order of magnitude. I wasn't sure if you consider quoting performance to be worth the extra dependency, though. I'd be happy to make that change as well if you think it's worth it.

This sounds like a good idea and I'd definitely be happy to add memchr as a dependency. If it's convenient for you, adding it into this PR is fine.

@fhartwig
Copy link
Contributor Author

I've pushed another commit for the memchr change. I only made this PR because I thought it was a no-downsides performance improvement, but I hadn't considered compatibility with older compilers, so feel free to close this if you prefer.

@BurntSushi BurntSushi merged commit fdab399 into BurntSushi:master Oct 13, 2016
@BurntSushi
Copy link
Owner

Awesome, thank you!

Backwards compatibility is important, but it's been a while since we had a version bump, so I'm fine with doing that.

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.

None yet

2 participants