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

Vec tweaks #13241

Merged
merged 2 commits into from
Apr 2, 2014
Merged

Vec tweaks #13241

merged 2 commits into from
Apr 2, 2014

Conversation

stepancheg
Copy link
Contributor

  • push_all* operations should reserve capacity before pushing data to avoid unnecessary reallocations
  • reserve_exact should never shrink, as specified in documentation

@@ -230,6 +230,8 @@ impl<T: Clone> Vec<T> {
/// ```
#[inline]
pub fn push_all(&mut self, other: &[T]) {
self.reserve_additional(other.len());

Copy link
Member

Choose a reason for hiding this comment

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

I think this method could be written as just:

fn push_all(&mut self, other: &[T]) {
     self.extend(other.iter().map(|e| e.clone())
}

and similarly self.extend(other.move_iter()) for push_all_move. The extend implementation includes the size reservation, and so this is more DRY etc.

reserve_exact should not shrink according to documentation.
It is shorter and also fixes missed reserve call.
@stepancheg
Copy link
Contributor Author

Updated patch: push_all* now calls extend.

bors added a commit that referenced this pull request Apr 2, 2014
* push_all* operations should reserve capacity before pushing data to avoid unnecessary reallocations
* reserve_exact should never shrink, as specified in documentation
@bors bors closed this Apr 2, 2014
@bors bors merged commit 026d206 into rust-lang:master Apr 2, 2014
Jarcho pushed a commit to Jarcho/rust that referenced this pull request Aug 24, 2024
…xFrednet

Fix confusing message in double_must_use lint

Close rust-lang#13003
As mentioned at rust-lang#13003 it isn't quite clear what it means "an empty `#[must_use]` attribute" so clarify it

changelog: [none]
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