Skip to content

Commit 29a8a73

Browse files
committed
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.
2 parents 7e456aa + f7e974e commit 29a8a73

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

src/libstd/collections/hash/map.rs

+3
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,9 @@ impl<K, V, S> HashMap<K, V, S>
588588
impl<K: Hash + Eq, V> HashMap<K, V, RandomState> {
589589
/// Creates an empty `HashMap`.
590590
///
591+
/// The hash map is initially created with a capacity of 0, so it will not allocate until it
592+
/// is first inserted into.
593+
///
591594
/// # Examples
592595
///
593596
/// ```

src/libstd/collections/hash/set.rs

+3
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,9 @@ pub struct HashSet<T, S = RandomState> {
125125
impl<T: Hash + Eq> HashSet<T, RandomState> {
126126
/// Creates an empty `HashSet`.
127127
///
128+
/// The hash set is initially created with a capacity of 0, so it will not allocate until it
129+
/// is first inserted into.
130+
///
128131
/// # Examples
129132
///
130133
/// ```

0 commit comments

Comments
 (0)