]> git.lizzy.rs Git - rust.git/commitdiff
Refactor macro comment and add resize with zeros example
authormandeep <mandeep@users.noreply.github.com>
Tue, 9 Oct 2018 05:51:22 +0000 (01:51 -0400)
committermandeep <mandeep@users.noreply.github.com>
Tue, 9 Oct 2018 05:51:22 +0000 (01:51 -0400)
src/liballoc/vec.rs

index 3188de512662c9290deafc77bc3b39fbdc4d3f75..f7a0bbdceafc93325359fbb83a51b413548db0da 100644 (file)
 /// ```
 ///
 /// It can also initialize each element of a `Vec<T>` with a given value.
-/// Initializing a `Vec<T>` in this manner is the most efficient and safest way to allocate a
-/// vector of zeros as previously zeroed memory is requested from the operating system:
+/// This may be more efficient than performing allocation and initialization
+/// in separate steps, especially when initializing a vector of zeros:
 ///
 /// ```
 /// let vec = vec![0; 5];
 /// assert_eq!(vec, [0, 0, 0, 0, 0]);
+///
+/// // The following is equivalent, but potentially slower:
+/// let mut vec1 = Vec::with_capacity(5);
+/// vec1.resize(5, 0);
 /// ```
 ///
 /// Use a `Vec<T>` as an efficient stack: