diff options
| author | mandeep <mandeep@users.noreply.github.com> | 2018-10-09 01:51:22 -0400 |
|---|---|---|
| committer | mandeep <mandeep@users.noreply.github.com> | 2018-10-09 01:51:22 -0400 |
| commit | 1e584bf5c9858bee54a9fbff25ab28b2ad29eb57 (patch) | |
| tree | 1906b83cbcbaf6e6646fdb8c2d948b8ae5b8cbde /src/liballoc | |
| parent | 82444aa753180c9c13028066ae9ddc4933dc610d (diff) | |
| download | rust-1e584bf5c9858bee54a9fbff25ab28b2ad29eb57.tar.gz rust-1e584bf5c9858bee54a9fbff25ab28b2ad29eb57.zip | |
Refactor macro comment and add resize with zeros example
Diffstat (limited to 'src/liballoc')
| -rw-r--r-- | src/liballoc/vec.rs | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/src/liballoc/vec.rs b/src/liballoc/vec.rs index 3188de51266..f7a0bbdceaf 100644 --- a/src/liballoc/vec.rs +++ b/src/liballoc/vec.rs @@ -121,12 +121,16 @@ use raw_vec::RawVec; /// ``` /// /// 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: |
