Skip to content

std::vec: Sane implementations for connect_vec and concat_vec #9583

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 3 commits into from
Sep 28, 2013
Merged

std::vec: Sane implementations for connect_vec and concat_vec #9583

merged 3 commits into from
Sep 28, 2013

Conversation

bluss
Copy link
Member

@bluss bluss commented Sep 28, 2013

std::vec: Sane implementations for connect_vec and concat_vec

Avoid unnecessary copying of subvectors, and calculate the needed space
beforehand. These implementations are simple but better than the
previous.

Also only implement it once, for all Vector<T> using:

impl<'self, T: Clone, V: Vector<T>> VectorVector<T> for &'self [V]

Closes #9581

@bluss
Copy link
Member Author

bluss commented Sep 28, 2013

Can we remove all the free functions connect, concat, connect_slice, concat_slice?

@huonw
Copy link
Member

huonw commented Sep 28, 2013

Yes, remove them.

impl<'self, T:Clone> VectorVector<T> for &'self [~[T]] {
/// Flattens a vector of slices of T into a single vector of T.
impl<'self, T: Clone, V: Vector<T>> VectorVector<T> for &'self [V] {
/// Flattens a vector of vectors of T into a single vector of T.
Copy link
Member

Choose a reason for hiding this comment

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

The documentation is being moved to the traits for these types of impls, so we might as well do it here too.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good idea

@bluss
Copy link
Member Author

bluss commented Sep 28, 2013

Success

before
test vec::bench::concat ... bench: 74818 ns/iter (+/- 408)
test vec::bench::connect ... bench: 87066 ns/iter (+/- 376)

after
test vec::bench::concat ... bench: 17724 ns/iter (+/- 126)
test vec::bench::connect ... bench: 18353 ns/iter (+/- 691)

blake2-ppc added 2 commits September 28, 2013 05:25
Avoid unnecessary copying of subvectors, and calculate the needed space
beforehand. These implementations are simple but better than the
previous.

Also only implement it once, for all `Vector<T>` using:

    impl<'self, T: Clone, V: Vector<T>> VectorVector<T> for &'self [V]

performance improved according to the bench test:

    before
    test vec::bench::concat ... bench: 74818 ns/iter (+/- 408)
    test vec::bench::connect ... bench: 87066 ns/iter (+/- 376)

    after
    test vec::bench::concat ... bench: 17724 ns/iter (+/- 126)
    test vec::bench::connect ... bench: 18353 ns/iter (+/- 691)

Closes #9581
std::vec::{concat, connect, concat_slices, connect_slices} are replaced
by the already existing trait methods .concat_vec() and .connect_vec().
@bluss
Copy link
Member Author

bluss commented Sep 28, 2013

thanks~

bors added a commit that referenced this pull request Sep 28, 2013
std::vec: Sane implementations for connect_vec and concat_vec

Avoid unnecessary copying of subvectors, and calculate the needed space
beforehand. These implementations are simple but better than the
previous.

Also only implement it once, for all `Vector<T>` using:

    impl<'self, T: Clone, V: Vector<T>> VectorVector<T> for &'self [V]

Closes #9581
@bors bors closed this Sep 28, 2013
@bors bors merged commit 3709aa7 into rust-lang:master Sep 28, 2013
@bluss bluss deleted the connect-vec branch September 28, 2013 16:43
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.

std::vec's connect_vec and concat_vec are inefficient
3 participants