Skip to content

Commit 1e584bf

Browse files
committed
Refactor macro comment and add resize with zeros example
1 parent 82444aa commit 1e584bf

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

Diff for: src/liballoc/vec.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,16 @@ use raw_vec::RawVec;
121121
/// ```
122122
///
123123
/// It can also initialize each element of a `Vec<T>` with a given value.
124-
/// Initializing a `Vec<T>` in this manner is the most efficient and safest way to allocate a
125-
/// vector of zeros as previously zeroed memory is requested from the operating system:
124+
/// This may be more efficient than performing allocation and initialization
125+
/// in separate steps, especially when initializing a vector of zeros:
126126
///
127127
/// ```
128128
/// let vec = vec![0; 5];
129129
/// assert_eq!(vec, [0, 0, 0, 0, 0]);
130+
///
131+
/// // The following is equivalent, but potentially slower:
132+
/// let mut vec1 = Vec::with_capacity(5);
133+
/// vec1.resize(5, 0);
130134
/// ```
131135
///
132136
/// Use a `Vec<T>` as an efficient stack:

0 commit comments

Comments
 (0)