diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2017-09-16 09:17:02 -0500 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2017-09-16 17:09:41 -0700 |
| commit | 0df4e926628291805e1aea10ae3ce565bb034a53 (patch) | |
| tree | 789c5c2063ba0120890bbe3fbd82f2a4f95c8049 /src | |
| parent | a47ca2291d593710a5f43cea9ddfaf1434decbb9 (diff) | |
| parent | f7e974e4322b53cdadddf2ca8c72eaf419d406f2 (diff) | |
| download | rust-0df4e926628291805e1aea10ae3ce565bb034a53.tar.gz rust-0df4e926628291805e1aea10ae3ce565bb034a53.zip | |
Rollup merge of #44609 - jonhoo:hash-alloc, r=steveklabnik
Mention that HashMap::new and HashSet::new do not allocate The docs for `HashMap::with_capacity` and `HashSet::with_capacity` already say that > If `capacity` is 0, the hash map/set will not allocate. However, the docs for `::new` do not say that the initial capacity is 0, and thus promise that a call to `::new` alone does not allocate. This PR fixes that.
Diffstat (limited to 'src')
| -rw-r--r-- | src/libstd/collections/hash/map.rs | 3 | ||||
| -rw-r--r-- | src/libstd/collections/hash/set.rs | 3 |
2 files changed, 6 insertions, 0 deletions
diff --git a/src/libstd/collections/hash/map.rs b/src/libstd/collections/hash/map.rs index fbb69ca9749..96af2272578 100644 --- a/src/libstd/collections/hash/map.rs +++ b/src/libstd/collections/hash/map.rs @@ -588,6 +588,9 @@ impl<K, V, S> HashMap<K, V, S> impl<K: Hash + Eq, V> HashMap<K, V, RandomState> { /// Creates an empty `HashMap`. /// + /// The hash map is initially created with a capacity of 0, so it will not allocate until it + /// is first inserted into. + /// /// # Examples /// /// ``` diff --git a/src/libstd/collections/hash/set.rs b/src/libstd/collections/hash/set.rs index 9771363d545..51698ce7c17 100644 --- a/src/libstd/collections/hash/set.rs +++ b/src/libstd/collections/hash/set.rs @@ -125,6 +125,9 @@ pub struct HashSet<T, S = RandomState> { impl<T: Hash + Eq> HashSet<T, RandomState> { /// Creates an empty `HashSet`. /// + /// The hash set is initially created with a capacity of 0, so it will not allocate until it + /// is first inserted into. + /// /// # Examples /// /// ``` |
