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

Suggest vec![…] instead of wall of vector.push(…) calls #1483

Closed
killercup opened this issue Jan 27, 2017 · 0 comments · Fixed by #6538
Closed

Suggest vec![…] instead of wall of vector.push(…) calls #1483

killercup opened this issue Jan 27, 2017 · 0 comments · Fixed by #6538
Labels
A-lint Area: New lints E-medium Call for participation: Medium difficulty level problem and requires some initial experience. T-middle Type: Probably requires verifiying types

Comments

@killercup
Copy link
Member

Looking at this code it seems safe to suggest to replace

let mut tris : Vec<Triangle<T, N>> = Vec::new();

tris.push(Triangle::new([p0, p11, p5], 0.));
tris.push(Triangle::new([p0, p5, p1], 0.));
tris.push(Triangle::new([p0, p1, p7], 0.));
tris.push(Triangle::new([p0, p7, p10], 0.));
tris.push(Triangle::new([p0, p10, p11], 0.));

with

let mut tris: Vec<Triangle<T, N>> = vec![
  Triangle::new([p0, p11, p5], 0.),
  Triangle::new([p0, p5, p1], 0.),
  Triangle::new([p0, p1, p7], 0.),
  Triangle::new([p0, p7, p10], 0.),
  Triangle::new([p0, p10, p11], 0.),
];

which has the added bonus of using .with_capacity (IIRC).

@mcarton mcarton added E-medium Call for participation: Medium difficulty level problem and requires some initial experience. A-lint Area: New lints T-middle Type: Probably requires verifiying types labels Jan 27, 2017
@bors bors closed this as completed in 976850b Jan 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: New lints E-medium Call for participation: Medium difficulty level problem and requires some initial experience. T-middle Type: Probably requires verifiying types
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants