@@ -619,19 +619,24 @@ impl<K, V, S> HashMap<K, V, S>
619
619
/// assert_eq!(letters.get(&'y'), None);
620
620
/// ```
621
621
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
622
- pub fn entry ( & mut self , key : K ) -> Entry < K , V , S > {
622
+ pub fn entry ( & mut self , key : K ) -> Entry < K , V > {
623
+ // Ideally we would put this in VacantEntry::insert, but Entry is not
624
+ // generic over the BuildHasher and adding a generic parameter would be
625
+ // a breaking change.
626
+ self . reserve ( 1 ) ;
627
+
623
628
let hash = make_hash ( & self . hash_builder , & key) ;
624
629
if let Some ( elem) = self . table . find ( hash, |q| q. 0 . eq ( & key) ) {
625
630
Entry :: Occupied ( OccupiedEntry {
626
631
key : Some ( key) ,
627
632
elem,
628
- table : self ,
633
+ table : & mut self . table ,
629
634
} )
630
635
} else {
631
636
Entry :: Vacant ( VacantEntry {
632
637
hash,
633
638
key,
634
- table : self ,
639
+ table : & mut self . table ,
635
640
} )
636
641
}
637
642
}
@@ -1734,20 +1739,20 @@ impl<'a, K, V, S> Debug for RawEntryBuilder<'a, K, V, S> {
1734
1739
/// [`HashMap`]: struct.HashMap.html
1735
1740
/// [`entry`]: struct.HashMap.html#method.entry
1736
1741
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1737
- pub enum Entry < ' a , K : ' a , V : ' a , S : ' a > {
1742
+ pub enum Entry < ' a , K : ' a , V : ' a > {
1738
1743
/// An occupied entry.
1739
1744
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1740
1745
Occupied ( #[ stable( feature = "rust1" , since = "1.0.0" ) ]
1741
- OccupiedEntry < ' a , K , V , S > ) ,
1746
+ OccupiedEntry < ' a , K , V > ) ,
1742
1747
1743
1748
/// A vacant entry.
1744
1749
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1745
1750
Vacant ( #[ stable( feature = "rust1" , since = "1.0.0" ) ]
1746
- VacantEntry < ' a , K , V , S > ) ,
1751
+ VacantEntry < ' a , K , V > ) ,
1747
1752
}
1748
1753
1749
1754
#[ stable( feature= "debug_hash_map" , since = "1.12.0" ) ]
1750
- impl < ' a , K : ' a + Debug , V : ' a + Debug , S : BuildHasher > Debug for Entry < ' a , K , V , S > {
1755
+ impl < ' a , K : ' a + Debug , V : ' a + Debug > Debug for Entry < ' a , K , V > {
1751
1756
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
1752
1757
match * self {
1753
1758
Vacant ( ref v) => {
@@ -1769,31 +1774,29 @@ impl<'a, K: 'a + Debug, V: 'a + Debug, S: BuildHasher> Debug for Entry<'a, K, V,
1769
1774
///
1770
1775
/// [`Entry`]: enum.Entry.html
1771
1776
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1772
- pub struct OccupiedEntry < ' a , K : ' a , V : ' a , S : ' a > {
1777
+ pub struct OccupiedEntry < ' a , K : ' a , V : ' a > {
1773
1778
key : Option < K > ,
1774
1779
elem : Bucket < ( K , V ) > ,
1775
- table : & ' a mut HashMap < K , V , S > ,
1780
+ table : & ' a mut RawTable < ( K , V ) > ,
1776
1781
}
1777
1782
1778
1783
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1779
- unsafe impl < ' a , K , V , S > Send for OccupiedEntry < ' a , K , V , S >
1784
+ unsafe impl < ' a , K , V > Send for OccupiedEntry < ' a , K , V >
1780
1785
where
1781
1786
K : Send ,
1782
1787
V : Send ,
1783
- S : Send ,
1784
1788
{
1785
1789
}
1786
1790
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1787
- unsafe impl < ' a , K , V , S > Sync for OccupiedEntry < ' a , K , V , S >
1791
+ unsafe impl < ' a , K , V > Sync for OccupiedEntry < ' a , K , V >
1788
1792
where
1789
1793
K : Sync ,
1790
1794
V : Sync ,
1791
- S : Sync ,
1792
1795
{
1793
1796
}
1794
1797
1795
1798
#[ stable( feature= "debug_hash_map" , since = "1.12.0" ) ]
1796
- impl < ' a , K : ' a + Debug , V : ' a + Debug , S > Debug for OccupiedEntry < ' a , K , V , S > {
1799
+ impl < ' a , K : ' a + Debug , V : ' a + Debug > Debug for OccupiedEntry < ' a , K , V > {
1797
1800
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
1798
1801
f. debug_struct ( "OccupiedEntry" )
1799
1802
. field ( "key" , self . key ( ) )
@@ -1807,14 +1810,14 @@ impl<'a, K: 'a + Debug, V: 'a + Debug, S> Debug for OccupiedEntry<'a, K, V, S> {
1807
1810
///
1808
1811
/// [`Entry`]: enum.Entry.html
1809
1812
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1810
- pub struct VacantEntry < ' a , K : ' a , V : ' a , S : ' a > {
1813
+ pub struct VacantEntry < ' a , K : ' a , V : ' a > {
1811
1814
hash : u64 ,
1812
1815
key : K ,
1813
- table : & ' a mut HashMap < K , V , S > ,
1816
+ table : & ' a mut RawTable < ( K , V ) > ,
1814
1817
}
1815
1818
1816
1819
#[ stable( feature= "debug_hash_map" , since = "1.12.0" ) ]
1817
- impl < ' a , K : ' a + Debug , V : ' a , S > Debug for VacantEntry < ' a , K , V , S > {
1820
+ impl < ' a , K : ' a + Debug , V : ' a > Debug for VacantEntry < ' a , K , V > {
1818
1821
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
1819
1822
f. debug_tuple ( "VacantEntry" )
1820
1823
. field ( self . key ( ) )
@@ -2091,7 +2094,7 @@ impl<'a, K, V> fmt::Debug for Drain<'a, K, V>
2091
2094
}
2092
2095
}
2093
2096
2094
- impl < ' a , K , V , S > Entry < ' a , K , V , S > {
2097
+ impl < ' a , K , V > Entry < ' a , K , V > {
2095
2098
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
2096
2099
/// Ensures a value is in the entry by inserting the default if empty, and returns
2097
2100
/// a mutable reference to the value in the entry.
@@ -2109,11 +2112,7 @@ impl<'a, K, V, S> Entry<'a, K, V, S> {
2109
2112
/// *map.entry("poneyland").or_insert(10) *= 2;
2110
2113
/// assert_eq!(map["poneyland"], 6);
2111
2114
/// ```
2112
- pub fn or_insert ( self , default : V ) -> & ' a mut V
2113
- where
2114
- K : Hash ,
2115
- S : BuildHasher ,
2116
- {
2115
+ pub fn or_insert ( self , default : V ) -> & ' a mut V {
2117
2116
match self {
2118
2117
Occupied ( entry) => entry. into_mut ( ) ,
2119
2118
Vacant ( entry) => entry. insert ( default) ,
@@ -2136,11 +2135,7 @@ impl<'a, K, V, S> Entry<'a, K, V, S> {
2136
2135
///
2137
2136
/// assert_eq!(map["poneyland"], "hoho".to_string());
2138
2137
/// ```
2139
- pub fn or_insert_with < F : FnOnce ( ) -> V > ( self , default : F ) -> & ' a mut V
2140
- where
2141
- K : Hash ,
2142
- S : BuildHasher ,
2143
- {
2138
+ pub fn or_insert_with < F : FnOnce ( ) -> V > ( self , default : F ) -> & ' a mut V {
2144
2139
match self {
2145
2140
Occupied ( entry) => entry. into_mut ( ) ,
2146
2141
Vacant ( entry) => entry. insert ( default ( ) ) ,
@@ -2200,7 +2195,7 @@ impl<'a, K, V, S> Entry<'a, K, V, S> {
2200
2195
2201
2196
}
2202
2197
2203
- impl < ' a , K , V : Default , S > Entry < ' a , K , V , S > {
2198
+ impl < ' a , K , V : Default > Entry < ' a , K , V > {
2204
2199
#[ stable( feature = "entry_or_default" , since = "1.28.0" ) ]
2205
2200
/// Ensures a value is in the entry by inserting the default value if empty,
2206
2201
/// and returns a mutable reference to the value in the entry.
@@ -2217,19 +2212,15 @@ impl<'a, K, V: Default, S> Entry<'a, K, V, S> {
2217
2212
/// assert_eq!(map["poneyland"], None);
2218
2213
/// # }
2219
2214
/// ```
2220
- pub fn or_default ( self ) -> & ' a mut V
2221
- where
2222
- K : Hash ,
2223
- S : BuildHasher ,
2224
- {
2215
+ pub fn or_default ( self ) -> & ' a mut V {
2225
2216
match self {
2226
2217
Occupied ( entry) => entry. into_mut ( ) ,
2227
2218
Vacant ( entry) => entry. insert ( Default :: default ( ) ) ,
2228
2219
}
2229
2220
}
2230
2221
}
2231
2222
2232
- impl < ' a , K , V , S > OccupiedEntry < ' a , K , V , S > {
2223
+ impl < ' a , K , V > OccupiedEntry < ' a , K , V > {
2233
2224
/// Gets a reference to the key in the entry.
2234
2225
///
2235
2226
/// # Examples
@@ -2267,7 +2258,7 @@ impl<'a, K, V, S> OccupiedEntry<'a, K, V, S> {
2267
2258
#[ stable( feature = "map_entry_recover_keys2" , since = "1.12.0" ) ]
2268
2259
pub fn remove_entry ( self ) -> ( K , V ) {
2269
2260
unsafe {
2270
- self . table . table . erase_no_drop ( & self . elem ) ;
2261
+ self . table . erase_no_drop ( & self . elem ) ;
2271
2262
self . elem . read ( )
2272
2263
}
2273
2264
}
@@ -2461,7 +2452,7 @@ impl<'a, K, V, S> OccupiedEntry<'a, K, V, S> {
2461
2452
}
2462
2453
}
2463
2454
2464
- impl < ' a , K : ' a , V : ' a , S : ' a > VacantEntry < ' a , K , V , S > {
2455
+ impl < ' a , K : ' a , V : ' a > VacantEntry < ' a , K , V > {
2465
2456
/// Gets a reference to the key that would be used when inserting a value
2466
2457
/// through the `VacantEntry`.
2467
2458
///
@@ -2514,15 +2505,8 @@ impl<'a, K: 'a, V: 'a, S: 'a> VacantEntry<'a, K, V, S> {
2514
2505
/// assert_eq!(map["poneyland"], 37);
2515
2506
/// ```
2516
2507
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
2517
- pub fn insert ( self , value : V ) -> & ' a mut V
2518
- where
2519
- K : Hash ,
2520
- S : BuildHasher ,
2521
- {
2522
- let hash_builder = & self . table . hash_builder ;
2523
- let bucket = self . table . table . insert ( self . hash , ( self . key , value) , |x| {
2524
- make_hash ( hash_builder, & x. 0 )
2525
- } ) ;
2508
+ pub fn insert ( self , value : V ) -> & ' a mut V {
2509
+ let bucket = self . table . insert_no_grow ( self . hash , ( self . key , value) ) ;
2526
2510
unsafe { & mut bucket. as_mut ( ) . 1 }
2527
2511
}
2528
2512
}
0 commit comments