@@ -77,20 +77,15 @@ struct RawBucket<K, V> {
7777 kval : * mut ( K , V ) ,
7878}
7979
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-
8780pub struct Bucket < K , V , M , S = ( ) > {
8881 raw : RawBucket < K , V > ,
8982 idx : usize ,
9083 capacity : usize ,
91- table : TableRef < M > ,
84+ table : M ,
9285}
9386
87+ impl < K , V > Copy for RawBucket < K , V > { }
88+
9489impl < K , V , M : Copy , S > Copy for Bucket < K , V , M , S > where M : Borrow < RawTable < K , V > > { }
9590
9691mod bucket {
@@ -151,20 +146,6 @@ fn can_alias_safehash_as_option() {
151146 assert_eq ! ( size_of:: <SafeHash >( ) , size_of:: <Option <SafeHash >>( ) )
152147}
153148
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-
168149impl < K , V > RawBucket < K , V > {
169150 unsafe fn offset ( self , count : isize ) -> RawBucket < K , V > {
170151 RawBucket {
@@ -180,15 +161,15 @@ impl<K, V, M, S> Borrow<RawTable<K, V>> for Bucket<K, V, M, S>
180161 where M : Borrow < RawTable < K , V > >
181162{
182163 fn borrow ( & self ) -> & RawTable < K , V > {
183- self . table . 0 . borrow ( )
164+ self . table . borrow ( )
184165 }
185166}
186167
187168impl < K , V , M , S > BorrowMut < RawTable < K , V > > for Bucket < K , V , M , S >
188169 where M : Borrow < RawTable < K , V > >
189170{
190171 fn borrow_mut ( & mut self ) -> & mut RawTable < K , V > {
191- self . table . 0 . borrow_mut ( )
172+ self . table . borrow_mut ( )
192173 }
193174}
194175
@@ -202,11 +183,11 @@ impl<K, V, M: Put> Put for FullBucket<K, V, M> {}
202183impl < K , V , M , S > Bucket < K , V , M , S > {
203184 /// Borrow a reference to the table.
204185 pub fn table ( & self ) -> & M {
205- & self . table . 0
186+ & self . table
206187 }
207188 /// Move out the reference to the table.
208189 pub fn into_table ( self ) -> M {
209- self . table . 0
190+ self . table
210191 }
211192 /// Get the raw index.
212193 pub fn index ( & self ) -> usize {
@@ -232,11 +213,10 @@ impl<K, V, M> Bucket<K, V, M> where M: Borrow<RawTable<K, V>> {
232213 pub fn at_index ( table : M , ib_index : uint )
233214 -> Result < Bucket < K , V , M > , Bucket < K , V , M , bucket:: TableIsEmpty > >
234215 {
235- let table = TableRef ( table) ;
236- let capacity = table. capacity ( ) ;
216+ let capacity = table. borrow ( ) . capacity ( ) ;
237217 let idx = ib_index & ( capacity - 1 ) ;
238218 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 ) } ,
240220 idx : idx,
241221 capacity : capacity,
242222 table : table,
@@ -254,7 +234,7 @@ impl<K, V, M> Bucket<K, V, M> where M: Borrow<RawTable<K, V>> {
254234
255235 /// Narrows down the range of iteration, which must be a power of 2.
256236 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( ) ) ;
258238 assert ! ( limit. is_power_of_two( ) ) ;
259239 self . capacity = limit;
260240 self
@@ -315,15 +295,15 @@ impl<K, V, M, S> Bucket<K, V, M, S> where M: Borrow<RawTable<K, V>> {
315295 raw : self . raw ,
316296 idx : self . idx ,
317297 capacity : self . capacity ,
318- table : TableRef ( self ) ,
298+ table : self ,
319299 }
320300 }
321301}
322302
323303impl < K , V , M > EmptyBucket < K , V , M > where M : Borrow < RawTable < K , V > > {
324304 pub fn gap_peek ( self ) -> Option < GapThenFull < K , V , M > > {
325305 let gap = Bucket {
326- table : TableRef ( ( ) ) ,
306+ table : ( ) ,
327307 idx : self . idx ,
328308 capacity : self . capacity ,
329309 raw : self . raw ,
@@ -341,7 +321,7 @@ impl<K, V, M> EmptyBucket<K, V, M> where M: Borrow<RawTable<K, V>> {
341321 }
342322}
343323
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 {
345325 /// Puts given key and value pair, along with the key's hash,
346326 /// into this bucket in the hashtable. Note how `self` is 'moved' into
347327 /// 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 {
356336 ptr:: write ( self . raw . kval , ( key, value) ) ;
357337 }
358338
359- self . table . size += 1 ;
339+ self . table . borrow_mut ( ) . size += 1 ;
360340
361341 self . unsafe_cast ( )
362342 }
@@ -413,7 +393,7 @@ impl<'t, K, V, M: 't> FullBucket<K, V, M> where M: BorrowMut<RawTable<K, V>> {
413393 /// This works similarly to `put`, building an `EmptyBucket` out of the
414394 /// taken bucket.
415395 pub fn take ( mut self ) -> ( EmptyBucket < K , V , M > , K , V ) {
416- self . table . size -= 1 ;
396+ self . table . borrow_mut ( ) . size -= 1 ;
417397
418398 unsafe {
419399 * self . raw . hash = None ;
@@ -618,7 +598,7 @@ impl<'t, K, V, M: 't> RawFullBucket<K, V, M> where M: BorrowMut<RawTable<K, V>>
618598pub struct RawFullBuckets < K , V , M > {
619599 raw : RawBucket < K , V > ,
620600 hashes_end : * mut Option < SafeHash > ,
621- table : TableRef < M > ,
601+ table : M ,
622602}
623603
624604// FIXME(#19839) Remove in favor of `#[derive(Clone)]`
0 commit comments