@@ -16,15 +16,14 @@ use clone::Clone;
16
16
use cmp;
17
17
use hash:: { Hash , Hasher } ;
18
18
use iter:: { Iterator , IteratorExt , ExactSizeIterator , count} ;
19
- use marker:: { Copy , Sized , self } ;
19
+ use marker:: { Copy , Send , Sync , Sized , self } ;
20
20
use mem:: { min_align_of, size_of} ;
21
21
use mem;
22
22
use num:: { Int , UnsignedInt } ;
23
23
use ops:: { Deref , DerefMut , Drop } ;
24
24
use option:: Option ;
25
25
use option:: Option :: { Some , None } ;
26
- use ptr:: { Unique , PtrExt , copy_nonoverlapping_memory, zero_memory} ;
27
- use ptr;
26
+ use ptr:: { self , PtrExt , copy_nonoverlapping_memory, zero_memory} ;
28
27
use rt:: heap:: { allocate, deallocate} ;
29
28
use collections:: hash_state:: HashState ;
30
29
@@ -70,12 +69,15 @@ const EMPTY_BUCKET: u64 = 0u64;
70
69
pub struct RawTable < K , V > {
71
70
capacity : uint ,
72
71
size : uint ,
73
- hashes : Unique < u64 > ,
72
+ hashes : * mut u64 ,
74
73
// Because K/V do not appear directly in any of the types in the struct,
75
74
// inform rustc that in fact instances of K and V are reachable from here.
76
75
marker : marker:: CovariantType < ( K , V ) > ,
77
76
}
78
77
78
+ unsafe impl < K : Send , V : Send > Send for RawTable < K , V > { }
79
+ unsafe impl < K : Sync , V : Sync > Sync for RawTable < K , V > { }
80
+
79
81
struct RawBucket < K , V > {
80
82
hash : * mut u64 ,
81
83
key : * mut K ,
@@ -565,7 +567,7 @@ impl<K, V> RawTable<K, V> {
565
567
return RawTable {
566
568
size : 0 ,
567
569
capacity : 0 ,
568
- hashes : Unique :: null ( ) ,
570
+ hashes : ptr :: null_mut ( ) ,
569
571
marker : marker:: CovariantType ,
570
572
} ;
571
573
}
@@ -604,7 +606,7 @@ impl<K, V> RawTable<K, V> {
604
606
RawTable {
605
607
capacity : capacity,
606
608
size : 0 ,
607
- hashes : Unique ( hashes) ,
609
+ hashes : hashes,
608
610
marker : marker:: CovariantType ,
609
611
}
610
612
}
@@ -613,14 +615,14 @@ impl<K, V> RawTable<K, V> {
613
615
let hashes_size = self . capacity * size_of :: < u64 > ( ) ;
614
616
let keys_size = self . capacity * size_of :: < K > ( ) ;
615
617
616
- let buffer = self . hashes . 0 as * mut u8 ;
618
+ let buffer = self . hashes as * mut u8 ;
617
619
let ( keys_offset, vals_offset) = calculate_offsets ( hashes_size,
618
620
keys_size, min_align_of :: < K > ( ) ,
619
621
min_align_of :: < V > ( ) ) ;
620
622
621
623
unsafe {
622
624
RawBucket {
623
- hash : self . hashes . 0 ,
625
+ hash : self . hashes ,
624
626
key : buffer. offset ( keys_offset as int ) as * mut K ,
625
627
val : buffer. offset ( vals_offset as int ) as * mut V
626
628
}
@@ -632,7 +634,7 @@ impl<K, V> RawTable<K, V> {
632
634
pub fn new ( capacity : uint ) -> RawTable < K , V > {
633
635
unsafe {
634
636
let ret = RawTable :: new_uninitialized ( capacity) ;
635
- zero_memory ( ret. hashes . 0 , capacity) ;
637
+ zero_memory ( ret. hashes , capacity) ;
636
638
ret
637
639
}
638
640
}
@@ -652,7 +654,7 @@ impl<K, V> RawTable<K, V> {
652
654
RawBuckets {
653
655
raw : self . first_bucket_raw ( ) ,
654
656
hashes_end : unsafe {
655
- self . hashes . 0 . offset ( self . capacity as int )
657
+ self . hashes . offset ( self . capacity as int )
656
658
} ,
657
659
marker : marker:: ContravariantLifetime ,
658
660
}
@@ -964,7 +966,7 @@ impl<K: Clone, V: Clone> Clone for RawTable<K, V> {
964
966
#[ unsafe_destructor]
965
967
impl < K , V > Drop for RawTable < K , V > {
966
968
fn drop ( & mut self ) {
967
- if self . hashes . 0 . is_null ( ) {
969
+ if self . hashes . is_null ( ) {
968
970
return ;
969
971
}
970
972
// This is done in reverse because we've likely partially taken
@@ -984,7 +986,7 @@ impl<K, V> Drop for RawTable<K, V> {
984
986
vals_size, min_align_of :: < V > ( ) ) ;
985
987
986
988
unsafe {
987
- deallocate ( self . hashes . 0 as * mut u8 , size, align) ;
989
+ deallocate ( self . hashes as * mut u8 , size, align) ;
988
990
// Remember how everything was allocated out of one buffer
989
991
// during initialization? We only need one call to free here.
990
992
}
0 commit comments