@@ -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 {
@@ -170,20 +165,6 @@ fn can_alias_safehash_as_option() {
170
165
assert_eq ! ( size_of:: <SafeHash >( ) , size_of:: <Option <SafeHash >>( ) )
171
166
}
172
167
173
- impl < K , V , M > Deref for TableRef < M > where M : Borrow < RawTable < K , V > > {
174
- type Target = RawTable < K , V > ;
175
-
176
- fn deref ( & self ) -> & RawTable < K , V > {
177
- self . 0 . borrow ( )
178
- }
179
- }
180
-
181
- impl < K , V , M > DerefMut for TableRef < M > where M : Borrow < RawTable < K , V > > {
182
- fn deref_mut ( & mut self ) -> & mut RawTable < K , V > {
183
- self . 0 . borrow_mut ( )
184
- }
185
- }
186
-
187
168
impl < K , V > RawBucket < K , V > {
188
169
unsafe fn offset ( self , count : isize ) -> RawBucket < K , V > {
189
170
RawBucket {
@@ -199,15 +180,15 @@ impl<K, V, M, S> Borrow<RawTable<K, V>> for Bucket<K, V, M, S>
199
180
where M : Borrow < RawTable < K , V > >
200
181
{
201
182
fn borrow ( & self ) -> & RawTable < K , V > {
202
- self . table . 0 . borrow ( )
183
+ self . table . borrow ( )
203
184
}
204
185
}
205
186
206
187
impl < K , V , M , S > BorrowMut < RawTable < K , V > > for Bucket < K , V , M , S >
207
188
where M : Borrow < RawTable < K , V > >
208
189
{
209
190
fn borrow_mut ( & mut self ) -> & mut RawTable < K , V > {
210
- self . table . 0 . borrow_mut ( )
191
+ self . table . borrow_mut ( )
211
192
}
212
193
}
213
194
@@ -221,11 +202,11 @@ impl<K, V, M: Put> Put for FullBucket<K, V, M> {}
221
202
impl < K , V , M , S > Bucket < K , V , M , S > {
222
203
/// Borrow a reference to the table.
223
204
pub fn table ( & self ) -> & M {
224
- & self . table . 0
205
+ & self . table
225
206
}
226
207
/// Move out the reference to the table.
227
208
pub fn into_table ( self ) -> M {
228
- self . table . 0
209
+ self . table
229
210
}
230
211
/// Get the raw index.
231
212
pub fn index ( & self ) -> usize {
@@ -251,11 +232,10 @@ impl<K, V, M> Bucket<K, V, M> where M: Borrow<RawTable<K, V>> {
251
232
pub fn at_index ( table : M , ib_index : uint )
252
233
-> Result < Bucket < K , V , M > , Bucket < K , V , M , bucket:: TableIsEmpty > >
253
234
{
254
- let table = TableRef ( table) ;
255
- let capacity = table. capacity ( ) ;
235
+ let capacity = table. borrow ( ) . capacity ( ) ;
256
236
let idx = ib_index & ( capacity - 1 ) ;
257
237
let bucket: Bucket < K , V , M > = Bucket {
258
- raw : unsafe { table. first_bucket_raw ( ) . offset ( idx as isize ) } ,
238
+ raw : unsafe { table. borrow ( ) . first_bucket_raw ( ) . offset ( idx as isize ) } ,
259
239
idx : idx,
260
240
capacity : capacity,
261
241
table : table,
@@ -273,7 +253,7 @@ impl<K, V, M> Bucket<K, V, M> where M: Borrow<RawTable<K, V>> {
273
253
274
254
/// Narrows down the range of iteration, which must be a power of 2.
275
255
pub fn iter_to ( mut self , limit : usize ) -> Bucket < K , V , M > {
276
- assert ! ( limit <= self . table. capacity( ) ) ;
256
+ assert ! ( limit <= self . table. borrow ( ) . capacity( ) ) ;
277
257
assert ! ( limit. is_power_of_two( ) ) ;
278
258
self . capacity = limit;
279
259
self
@@ -334,15 +314,15 @@ impl<K, V, M, S> Bucket<K, V, M, S> where M: Borrow<RawTable<K, V>> {
334
314
raw : self . raw ,
335
315
idx : self . idx ,
336
316
capacity : self . capacity ,
337
- table : TableRef ( self ) ,
317
+ table : self ,
338
318
}
339
319
}
340
320
}
341
321
342
322
impl < K , V , M > EmptyBucket < K , V , M > where M : Borrow < RawTable < K , V > > {
343
323
pub fn gap_peek ( self ) -> Option < GapThenFull < K , V , M > > {
344
324
let gap = Bucket {
345
- table : TableRef ( ( ) ) ,
325
+ table : ( ) ,
346
326
idx : self . idx ,
347
327
capacity : self . capacity ,
348
328
raw : self . raw ,
@@ -360,7 +340,7 @@ impl<K, V, M> EmptyBucket<K, V, M> where M: Borrow<RawTable<K, V>> {
360
340
}
361
341
}
362
342
363
- impl < K , V , M > EmptyBucket < K , V , M > where M : Borrow < RawTable < K , V > > , M : Put {
343
+ impl < K , V , M > EmptyBucket < K , V , M > where M : BorrowMut < RawTable < K , V > > , M : Put {
364
344
/// Puts given key and value pair, along with the key's hash,
365
345
/// into this bucket in the hashtable. Note how `self` is 'moved' into
366
346
/// this function, because this slot will no longer be empty when
@@ -375,7 +355,7 @@ impl<K, V, M> EmptyBucket<K, V, M> where M: Borrow<RawTable<K, V>>, M: Put {
375
355
ptr:: write ( self . raw . kval , ( key, value) ) ;
376
356
}
377
357
378
- self . table . size += 1 ;
358
+ self . table . borrow_mut ( ) . size += 1 ;
379
359
380
360
self . unsafe_cast ( )
381
361
}
@@ -432,7 +412,7 @@ impl<'t, K, V, M: 't> FullBucket<K, V, M> where M: BorrowMut<RawTable<K, V>> {
432
412
/// This works similarly to `put`, building an `EmptyBucket` out of the
433
413
/// taken bucket.
434
414
pub fn take ( mut self ) -> ( EmptyBucket < K , V , M > , K , V ) {
435
- self . table . size -= 1 ;
415
+ self . table . borrow_mut ( ) . size -= 1 ;
436
416
437
417
unsafe {
438
418
* self . raw . hash = None ;
@@ -637,7 +617,7 @@ impl<'t, K, V, M: 't> RawFullBucket<K, V, M> where M: BorrowMut<RawTable<K, V>>
637
617
pub struct RawFullBuckets < K , V , M > {
638
618
raw : RawBucket < K , V > ,
639
619
hashes_end : * mut Option < SafeHash > ,
640
- table : TableRef < M > ,
620
+ table : M ,
641
621
}
642
622
643
623
// FIXME(#19839) Remove in favor of `#[derive(Clone)]`
0 commit comments