Skip to content

Commit 76b6e24

Browse files
author
Joeri Samson
committed
Optimize Buffer initialization
According to Clippy and the Rust issue tracker[0] you should use the vec! macro when initializing a vector to 0 bytes. [0] rust-lang/rust#5462
1 parent 1578492 commit 76b6e24

File tree

1 file changed

+1
-3
lines changed

1 file changed

+1
-3
lines changed

src/lib.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@
4949
//!
5050
use std::cmp;
5151
use std::io::{self,Write,Read};
52-
use std::iter::repeat;
5352

5453
/// the Buffer contains the underlying memory and data positions
5554
///
@@ -70,8 +69,7 @@ pub struct Buffer {
7069
impl Buffer {
7170
/// allocates a new buffer of maximum size `capacity`
7271
pub fn with_capacity(capacity: usize) -> Buffer {
73-
let mut v = Vec::with_capacity(capacity);
74-
v.extend(repeat(0).take(capacity));
72+
let v = vec![0; capacity];
7573
Buffer {
7674
memory: v,
7775
capacity: capacity,

0 commit comments

Comments
 (0)