Skip to content

Commit c1ff089

Browse files
committed
std: micro optimize Hash{Map,Set}::{new,with_capacity}
1 parent 8284ef6 commit c1ff089

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/libstd/collections/hashmap.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1033,11 +1033,13 @@ impl<K: Eq + Hash<S>, V, S, H: Hasher<S>> MutableMap<K, V> for HashMap<K, V, H>
10331033

10341034
impl<K: Hash + Eq, V> HashMap<K, V, RandomSipHasher> {
10351035
/// Create an empty HashMap.
1036+
#[inline]
10361037
pub fn new() -> HashMap<K, V, RandomSipHasher> {
10371038
HashMap::with_capacity(INITIAL_CAPACITY)
10381039
}
10391040

10401041
/// Creates an empty hash map with the given initial capacity.
1042+
#[inline]
10411043
pub fn with_capacity(capacity: uint) -> HashMap<K, V, RandomSipHasher> {
10421044
let hasher = RandomSipHasher::new();
10431045
HashMap::with_capacity_and_hasher(capacity, hasher)
@@ -1048,6 +1050,7 @@ impl<K: Eq + Hash<S>, V, S, H: Hasher<S>> HashMap<K, V, H> {
10481050
/// Creates an empty hashmap which will use the given hasher to hash keys.
10491051
///
10501052
/// The creates map has the default initial capacity.
1053+
#[inline]
10511054
pub fn with_hasher(hasher: H) -> HashMap<K, V, H> {
10521055
HashMap::with_capacity_and_hasher(INITIAL_CAPACITY, hasher)
10531056
}
@@ -1059,6 +1062,7 @@ impl<K: Eq + Hash<S>, V, S, H: Hasher<S>> HashMap<K, V, H> {
10591062
/// is designed to allow HashMaps to be resistant to attacks that
10601063
/// cause many collisions and very poor performance. Setting it
10611064
/// manually using this function can expose a DoS attack vector.
1065+
#[inline]
10621066
pub fn with_capacity_and_hasher(capacity: uint, hasher: H) -> HashMap<K, V, H> {
10631067
let cap = num::next_power_of_two(max(INITIAL_CAPACITY, capacity));
10641068
HashMap {
@@ -1526,12 +1530,14 @@ impl<T: Eq + Hash<S>, S, H: Hasher<S>> MutableSet<T> for HashSet<T, H> {
15261530

15271531
impl<T: Hash + Eq> HashSet<T, RandomSipHasher> {
15281532
/// Create an empty HashSet
1533+
#[inline]
15291534
pub fn new() -> HashSet<T, RandomSipHasher> {
15301535
HashSet::with_capacity(INITIAL_CAPACITY)
15311536
}
15321537

15331538
/// Create an empty HashSet with space for at least `n` elements in
15341539
/// the hash table.
1540+
#[inline]
15351541
pub fn with_capacity(capacity: uint) -> HashSet<T, RandomSipHasher> {
15361542
HashSet { map: HashMap::with_capacity(capacity) }
15371543
}
@@ -1542,6 +1548,7 @@ impl<T: Eq + Hash<S>, S, H: Hasher<S>> HashSet<T, H> {
15421548
/// keys.
15431549
///
15441550
/// The hash set is also created with the default initial capacity.
1551+
#[inline]
15451552
pub fn with_hasher(hasher: H) -> HashSet<T, H> {
15461553
HashSet::with_capacity_and_hasher(INITIAL_CAPACITY, hasher)
15471554
}
@@ -1553,6 +1560,7 @@ impl<T: Eq + Hash<S>, S, H: Hasher<S>> HashSet<T, H> {
15531560
/// is designed to allow `HashSet`s to be resistant to attacks that
15541561
/// cause many collisions and very poor performance. Setting it
15551562
/// manually using this function can expose a DoS attack vector.
1563+
#[inline]
15561564
pub fn with_capacity_and_hasher(capacity: uint, hasher: H) -> HashSet<T, H> {
15571565
HashSet { map: HashMap::with_capacity_and_hasher(capacity, hasher) }
15581566
}

0 commit comments

Comments
 (0)