@@ -17,7 +17,7 @@ use marker;
17
17
use mem:: { align_of, size_of} ;
18
18
use mem;
19
19
use ops:: { Deref , DerefMut } ;
20
- use ptr:: { self , Unique } ;
20
+ use ptr:: { self , Unique , Shared } ;
21
21
22
22
use self :: BucketState :: * ;
23
23
@@ -754,7 +754,8 @@ impl<K, V> RawTable<K, V> {
754
754
hashes_end : hashes_end,
755
755
marker : marker:: PhantomData ,
756
756
} ,
757
- table : self ,
757
+ table : unsafe { Shared :: new ( self ) } ,
758
+ marker : marker:: PhantomData ,
758
759
}
759
760
}
760
761
@@ -897,8 +898,9 @@ unsafe impl<K: Send, V: Send> Send for IntoIter<K, V> {}
897
898
898
899
/// Iterator over the entries in a table, clearing the table.
899
900
pub struct Drain < ' a , K : ' a , V : ' a > {
900
- table : & ' a mut RawTable < K , V > ,
901
+ table : Shared < RawTable < K , V > > ,
901
902
iter : RawBuckets < ' static , K , V > ,
903
+ marker : marker:: PhantomData < & ' a RawTable < K , V > > ,
902
904
}
903
905
904
906
unsafe impl < ' a , K : Sync , V : Sync > Sync for Drain < ' a , K , V > { }
@@ -973,8 +975,8 @@ impl<'a, K, V> Iterator for Drain<'a, K, V> {
973
975
#[ inline]
974
976
fn next ( & mut self ) -> Option < ( SafeHash , K , V ) > {
975
977
self . iter . next ( ) . map ( |bucket| {
976
- self . table . size -= 1 ;
977
978
unsafe {
979
+ ( * * self . table ) . size -= 1 ;
978
980
( SafeHash { hash : ptr:: replace ( bucket. hash , EMPTY_BUCKET ) } ,
979
981
ptr:: read ( bucket. key ) ,
980
982
ptr:: read ( bucket. val ) )
@@ -983,13 +985,15 @@ impl<'a, K, V> Iterator for Drain<'a, K, V> {
983
985
}
984
986
985
987
fn size_hint ( & self ) -> ( usize , Option < usize > ) {
986
- let size = self . table . size ( ) ;
988
+ let size = unsafe { ( * * self . table ) . size ( ) } ;
987
989
( size, Some ( size) )
988
990
}
989
991
}
990
992
impl < ' a , K , V > ExactSizeIterator for Drain < ' a , K , V > {
991
993
fn len ( & self ) -> usize {
992
- self . table . size ( )
994
+ unsafe {
995
+ ( * * self . table ) . size ( )
996
+ }
993
997
}
994
998
}
995
999
0 commit comments