@@ -77,20 +77,15 @@ struct RawBucket<K, V> {
77
77
kval : * mut ( K , V ) ,
78
78
}
79
79
80
- impl < K , V > Copy for RawBucket < K , V > { }
81
-
82
- #[ derive( Clone ) ]
83
- pub struct TableRef < M > ( pub M ) ;
84
-
85
- impl < M : Copy > Copy for TableRef < M > { }
86
-
87
80
pub struct Bucket < K , V , M , S = ( ) > {
88
81
raw : RawBucket < K , V > ,
89
82
idx : usize ,
90
83
capacity : usize ,
91
- table : TableRef < M > ,
84
+ table : M ,
92
85
}
93
86
87
+ impl < K , V > Copy for RawBucket < K , V > { }
88
+
94
89
impl < K , V , M : Copy , S > Copy for Bucket < K , V , M , S > where M : Borrow < RawTable < K , V > > { }
95
90
96
91
mod bucket {
@@ -151,20 +146,6 @@ fn can_alias_safehash_as_option() {
151
146
assert_eq ! ( size_of:: <SafeHash >( ) , size_of:: <Option <SafeHash >>( ) )
152
147
}
153
148
154
- impl < K , V , M > Deref for TableRef < M > where M : Borrow < RawTable < K , V > > {
155
- type Target = RawTable < K , V > ;
156
-
157
- fn deref ( & self ) -> & RawTable < K , V > {
158
- self . 0 . borrow ( )
159
- }
160
- }
161
-
162
- impl < K , V , M > DerefMut for TableRef < M > where M : Borrow < RawTable < K , V > > {
163
- fn deref_mut ( & mut self ) -> & mut RawTable < K , V > {
164
- self . 0 . borrow_mut ( )
165
- }
166
- }
167
-
168
149
impl < K , V > RawBucket < K , V > {
169
150
unsafe fn offset ( self , count : isize ) -> RawBucket < K , V > {
170
151
RawBucket {
@@ -180,15 +161,15 @@ impl<K, V, M, S> Borrow<RawTable<K, V>> for Bucket<K, V, M, S>
180
161
where M : Borrow < RawTable < K , V > >
181
162
{
182
163
fn borrow ( & self ) -> & RawTable < K , V > {
183
- self . table . 0 . borrow ( )
164
+ self . table . borrow ( )
184
165
}
185
166
}
186
167
187
168
impl < K , V , M , S > BorrowMut < RawTable < K , V > > for Bucket < K , V , M , S >
188
169
where M : Borrow < RawTable < K , V > >
189
170
{
190
171
fn borrow_mut ( & mut self ) -> & mut RawTable < K , V > {
191
- self . table . 0 . borrow_mut ( )
172
+ self . table . borrow_mut ( )
192
173
}
193
174
}
194
175
@@ -202,11 +183,11 @@ impl<K, V, M: Put> Put for FullBucket<K, V, M> {}
202
183
impl < K , V , M , S > Bucket < K , V , M , S > {
203
184
/// Borrow a reference to the table.
204
185
pub fn table ( & self ) -> & M {
205
- & self . table . 0
186
+ & self . table
206
187
}
207
188
/// Move out the reference to the table.
208
189
pub fn into_table ( self ) -> M {
209
- self . table . 0
190
+ self . table
210
191
}
211
192
/// Get the raw index.
212
193
pub fn index ( & self ) -> usize {
@@ -232,11 +213,10 @@ impl<K, V, M> Bucket<K, V, M> where M: Borrow<RawTable<K, V>> {
232
213
pub fn at_index ( table : M , ib_index : uint )
233
214
-> Result < Bucket < K , V , M > , Bucket < K , V , M , bucket:: TableIsEmpty > >
234
215
{
235
- let table = TableRef ( table) ;
236
- let capacity = table. capacity ( ) ;
216
+ let capacity = table. borrow ( ) . capacity ( ) ;
237
217
let idx = ib_index & ( capacity - 1 ) ;
238
218
let bucket: Bucket < K , V , M > = Bucket {
239
- raw : unsafe { table. first_bucket_raw ( ) . offset ( idx as isize ) } ,
219
+ raw : unsafe { table. borrow ( ) . first_bucket_raw ( ) . offset ( idx as isize ) } ,
240
220
idx : idx,
241
221
capacity : capacity,
242
222
table : table,
@@ -254,7 +234,7 @@ impl<K, V, M> Bucket<K, V, M> where M: Borrow<RawTable<K, V>> {
254
234
255
235
/// Narrows down the range of iteration, which must be a power of 2.
256
236
pub fn iter_to ( mut self , limit : usize ) -> Bucket < K , V , M > {
257
- assert ! ( limit <= self . table. capacity( ) ) ;
237
+ assert ! ( limit <= self . table. borrow ( ) . capacity( ) ) ;
258
238
assert ! ( limit. is_power_of_two( ) ) ;
259
239
self . capacity = limit;
260
240
self
@@ -315,15 +295,15 @@ impl<K, V, M, S> Bucket<K, V, M, S> where M: Borrow<RawTable<K, V>> {
315
295
raw : self . raw ,
316
296
idx : self . idx ,
317
297
capacity : self . capacity ,
318
- table : TableRef ( self ) ,
298
+ table : self ,
319
299
}
320
300
}
321
301
}
322
302
323
303
impl < K , V , M > EmptyBucket < K , V , M > where M : Borrow < RawTable < K , V > > {
324
304
pub fn gap_peek ( self ) -> Option < GapThenFull < K , V , M > > {
325
305
let gap = Bucket {
326
- table : TableRef ( ( ) ) ,
306
+ table : ( ) ,
327
307
idx : self . idx ,
328
308
capacity : self . capacity ,
329
309
raw : self . raw ,
@@ -341,7 +321,7 @@ impl<K, V, M> EmptyBucket<K, V, M> where M: Borrow<RawTable<K, V>> {
341
321
}
342
322
}
343
323
344
- impl < K , V , M > EmptyBucket < K , V , M > where M : Borrow < RawTable < K , V > > , M : Put {
324
+ impl < K , V , M > EmptyBucket < K , V , M > where M : BorrowMut < RawTable < K , V > > , M : Put {
345
325
/// Puts given key and value pair, along with the key's hash,
346
326
/// into this bucket in the hashtable. Note how `self` is 'moved' into
347
327
/// this function, because this slot will no longer be empty when
@@ -356,7 +336,7 @@ impl<K, V, M> EmptyBucket<K, V, M> where M: Borrow<RawTable<K, V>>, M: Put {
356
336
ptr:: write ( self . raw . kval , ( key, value) ) ;
357
337
}
358
338
359
- self . table . size += 1 ;
339
+ self . table . borrow_mut ( ) . size += 1 ;
360
340
361
341
self . unsafe_cast ( )
362
342
}
@@ -413,7 +393,7 @@ impl<'t, K, V, M: 't> FullBucket<K, V, M> where M: BorrowMut<RawTable<K, V>> {
413
393
/// This works similarly to `put`, building an `EmptyBucket` out of the
414
394
/// taken bucket.
415
395
pub fn take ( mut self ) -> ( EmptyBucket < K , V , M > , K , V ) {
416
- self . table . size -= 1 ;
396
+ self . table . borrow_mut ( ) . size -= 1 ;
417
397
418
398
unsafe {
419
399
* self . raw . hash = None ;
@@ -618,7 +598,7 @@ impl<'t, K, V, M: 't> RawFullBucket<K, V, M> where M: BorrowMut<RawTable<K, V>>
618
598
pub struct RawFullBuckets < K , V , M > {
619
599
raw : RawBucket < K , V > ,
620
600
hashes_end : * mut Option < SafeHash > ,
621
- table : TableRef < M > ,
601
+ table : M ,
622
602
}
623
603
624
604
// FIXME(#19839) Remove in favor of `#[derive(Clone)]`
0 commit comments