Simplify Vec2D::new() a bit
authorunc0rr
Sun, 14 Oct 2018 21:26:15 +0200
changeset 13936 f64790b2a725
parent 13935 ef50e4f59b8f
child 13937 cd437d76978a
Simplify Vec2D::new() a bit
rust/vec2d/src/lib.rs
--- a/rust/vec2d/src/lib.rs	Sun Oct 14 23:25:20 2018 +0300
+++ b/rust/vec2d/src/lib.rs	Sun Oct 14 21:26:15 2018 +0200
@@ -33,15 +33,11 @@
 
 impl<T: Copy> Vec2D<T> {
     pub fn new(width: usize, height: usize, value: T) -> Self {
-        let mut vec = Self {
-            data: Vec::new(),
+        Self {
+            data: vec![value; width * height],
             width,
             height,
-        };
-
-        vec.data.extend(iter::repeat(value).take(width * height));
-
-        vec
+        }
     }
 
     #[inline]