Skip to content

Commit 8f53c9a

Browse files
committed
Move entry fully into the core
1 parent f7a4a15 commit 8f53c9a

File tree

3 files changed

+16
-23
lines changed

3 files changed

+16
-23
lines changed

src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ mod mutable_keys;
7979
mod serde;
8080
mod util;
8181

82-
#[macro_use]
8382
mod map_core;
8483

8584
pub mod map;

src/map.rs

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use std::cmp::Ordering;
2424
use std::fmt;
2525

2626
use equivalent::Equivalent;
27-
use map_core::{IndexMapCore, Size};
27+
use map_core::IndexMapCore;
2828
use util::third;
2929
use {Bucket, Entries, HashValue};
3030

@@ -203,27 +203,13 @@ impl<K, V, S> IndexMap<K, V, S> {
203203
pub fn capacity(&self) -> usize {
204204
self.core.capacity()
205205
}
206-
207-
#[inline]
208-
fn size_class_is_64bit(&self) -> bool {
209-
self.core.size_class_is_64bit()
210-
}
211206
}
212207

213208
impl<K, V, S> IndexMap<K, V, S>
214209
where
215210
K: Hash + Eq,
216211
S: BuildHasher,
217212
{
218-
// FIXME: reduce duplication (compare with insert)
219-
fn entry_phase_1<Sz>(&mut self, key: K) -> Entry<K, V>
220-
where
221-
Sz: Size,
222-
{
223-
let hash = hash_elem_using(&self.hash_builder, &key);
224-
self.core.entry_phase_1::<Sz>(hash, key)
225-
}
226-
227213
/// Remove all key-value pairs in the map, while preserving its capacity.
228214
///
229215
/// Computes in **O(n)** time.
@@ -289,8 +275,8 @@ where
289275
///
290276
/// Computes in **O(1)** time (amortized average).
291277
pub fn entry(&mut self, key: K) -> Entry<K, V> {
292-
self.core.reserve_one();
293-
dispatch_32_vs_64!(self.entry_phase_1(key))
278+
let hash = hash_elem_using(&self.hash_builder, &key);
279+
self.core.entry(hash, key)
294280
}
295281

296282
/// Return an iterator over the key-value pairs of the map, in their order

src/map_core.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use {Bucket, HashValue};
2323

2424
/// Trait for the "size class". Either u32 or u64 depending on the index
2525
/// size needed to address an entry's index in self.core.entries.
26-
pub(crate) trait Size {
26+
trait Size {
2727
fn is_64_bit() -> bool;
2828
fn is_same_size<T: Size>() -> bool {
2929
Self::is_64_bit() == T::is_64_bit()
@@ -398,14 +398,14 @@ impl<K, V> IndexMapCore<K, V> {
398398

399399
// Return whether we need 32 or 64 bits to specify a bucket or entry index
400400
#[cfg(not(feature = "test_low_transition_point"))]
401-
pub(crate) fn size_class_is_64bit(&self) -> bool {
401+
fn size_class_is_64bit(&self) -> bool {
402402
usize::max_value() > u32::max_value() as usize
403403
&& self.raw_capacity() >= u32::max_value() as usize
404404
}
405405

406406
// for testing
407407
#[cfg(feature = "test_low_transition_point")]
408-
pub(crate) fn size_class_is_64bit(&self) -> bool {
408+
fn size_class_is_64bit(&self) -> bool {
409409
self.raw_capacity() >= 64
410410
}
411411

@@ -450,7 +450,7 @@ impl<K, V> IndexMapCore<K, V> {
450450

451451
#[inline(never)]
452452
// `Sz` is *current* Size class, before grow
453-
pub(crate) fn double_capacity<Sz>(&mut self)
453+
fn double_capacity<Sz>(&mut self)
454454
where
455455
Sz: Size,
456456
{
@@ -529,8 +529,16 @@ impl<K, V> IndexMapCore<K, V> {
529529
Some(self.swap_remove_found(probe, found))
530530
}
531531

532+
pub(crate) fn entry(&mut self, hash: HashValue, key: K) -> Entry<K, V>
533+
where
534+
K: Eq,
535+
{
536+
self.reserve_one();
537+
dispatch_32_vs_64!(self.entry_phase_1(hash, key))
538+
}
539+
532540
// FIXME: reduce duplication (compare with insert)
533-
pub(crate) fn entry_phase_1<Sz>(&mut self, hash: HashValue, key: K) -> Entry<K, V>
541+
fn entry_phase_1<Sz>(&mut self, hash: HashValue, key: K) -> Entry<K, V>
534542
where
535543
Sz: Size,
536544
K: Eq,

0 commit comments

Comments
 (0)