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

add append to vec with tests and benchmarks #21330

Conversation

JeffBelgum
Copy link
Contributor

Please review carefully. Contains unsafe and is my first commit to Rust.

Uses ptr::copy_nonoverlapping_memory. Attempts to handle zero-size types correctly.

@rust-highfive
Copy link
Collaborator

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @brson (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. The way Github handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see CONTRIBUTING.md for more information.

/// let mut vec2 = vec![4i, 5, 6];
/// vec.append(&mut vec2);
/// assert_eq!(vec, vec![1i, 2, 3, 4, 5, 6]);
/// assert_eq!(vec2, Vec::new::<i>());
Copy link
Contributor

Choose a reason for hiding this comment

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

Does vec![] not infer correctly here?

@Gankra
Copy link
Contributor

Gankra commented Jan 17, 2015

Generally we only add benchmarks when we're trying to establish that a change has a desired performance impact. Adding them for every feature is kinda unwieldy (just slows everything else down).

@Gankra
Copy link
Contributor

Gankra commented Jan 17, 2015

Actual code seems legit, just style nits.

👍

@JeffBelgum
Copy link
Contributor Author

I've addressed the previous comments.

@Gankra
Copy link
Contributor

Gankra commented Jan 17, 2015

Oh derp. Yeah no worries.

@@ -2777,4 +2823,54 @@ mod tests {
fn bench_clone_from_10_1000_0100(b: &mut Bencher) {
do_bench_clone_from(b, 10, 1000, 100)
}

fn do_bench_append(b: &mut Bencher, dst_len: uint, src_len: uint) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I would still drop these benches.

@Gankra
Copy link
Contributor

Gankra commented Jan 17, 2015

r=me with benches removed, and commits squashed.

@JeffBelgum JeffBelgum force-pushed the collections-reform-issue-19986-add-append-and-split-off branch from 74e4f3e to 08e712e Compare January 18, 2015 00:15
@JeffBelgum
Copy link
Contributor Author

r=Gankro

bors added a commit that referenced this pull request Jan 18, 2015
…-add-append-and-split-off, r=Gankro

Please review carefully. Contains unsafe and is my first commit to Rust.

Uses ptr::copy_nonoverlapping_memory. Attempts to handle zero-size types correctly.
@bors bors merged commit 08e712e into rust-lang:master Jan 18, 2015
@Gankra
Copy link
Contributor

Gankra commented Jan 18, 2015

Congrats!

Hope to see more from you in the future. 😄

@mneumann
Copy link
Contributor

I am a bit unhappy about the naming, as it's moving the elements out of the argument. I wouldn't expect that. But I don't have a better name for it...

@Gankra
Copy link
Contributor

Gankra commented Jan 19, 2015

This name was accepted in an RFC: rust-lang/rfcs#509

@mneumann
Copy link
Contributor

ok. would have been cleaner to have sth. like move in the name, suggesting that the items are actually moved, but then move_append sounds ugly. I am fine with append, but still it might be unintuitive and someone might expect the argument vector still to contain the values...

@andrewrk
Copy link

Why does move_append sound ugly? It describes exactly what the function does.

@mneumann
Copy link
Contributor

@andrewrk: Hm, after thinking about it, yes move_append describes exactly what it does! Given the fact that append in it's current form is an optimization so that you can reuse it's argument, I'd rather go with consuming it's argument append(&mut self, other: Self) and rename it's current form into the more-dangerous-to-use move_append(&mut self, other: &mut Self).

@mneumann
Copy link
Contributor

Ok, we have push_all which clones and append which moves. Without consulting the documentation it's not obvious to me which one does which.

@Gankra
Copy link
Contributor

Gankra commented Jan 21, 2015

basically nothing in Rust actually uses the term move

@Gankra
Copy link
Contributor

Gankra commented Jan 21, 2015

And push_all is a non-normative performance hack

@huonw
Copy link
Member

huonw commented Jan 21, 2015

basically nothing in Rust actually uses the term move

(There's move || ... closures.)

@mneumann
Copy link
Contributor

@gankro: In the past there was move_iter() IIRC which has been renamed to into_iter(). I am still living in the past :D

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.

8 participants