File tree 1 file changed +4
-12
lines changed
1 file changed +4
-12
lines changed Original file line number Diff line number Diff line change @@ -29,26 +29,18 @@ declare_clippy_lint! {
29
29
/// it involves two operations for allocating and initializing.
30
30
/// The `resize` call first allocates memory (since `Vec::new()` did not), and only *then* zero-initializes it.
31
31
///
32
- /// Writing `Vec::with_capacity(size)` followed by `vec.resize(len, 0)` is similar.
33
- /// The allocation shifts from `resize` to `with_capacity`,
34
- /// but the zero-initialization still happens separately,
35
- /// when it could be done in one call with `vec![0; len]` (`alloc_zeroed`).
36
- ///
37
32
/// ### Example
38
33
/// ```rust
39
34
/// # use core::iter::repeat;
40
35
/// # let len = 4;
41
- /// let mut vec1 = Vec::with_capacity(len );
36
+ /// let mut vec1 = Vec::new( );
42
37
/// vec1.resize(len, 0);
43
38
///
44
- /// let mut vec1 = Vec::with_capacity(len);
45
- /// vec1.resize(vec1.capacity(), 0);
46
- ///
47
39
/// let mut vec2 = Vec::with_capacity(len);
48
- /// vec2.extend(repeat(0).take( len) );
40
+ /// vec2.resize( len, 0 );
49
41
///
50
- /// let mut vec3 = Vec::new( );
51
- /// vec3.resize(len, 0 );
42
+ /// let mut vec3 = Vec::with_capacity(len );
43
+ /// vec3.extend(repeat(0).take(len) );
52
44
/// ```
53
45
///
54
46
/// Use instead:
You can’t perform that action at this time.
0 commit comments