@@ -717,26 +717,25 @@ fn calculate_offsets(hashes_size: usize,
717
717
( pairs_offset, end_of_pairs, oflo)
718
718
}
719
719
720
- // Returns a tuple of (minimum required malloc alignment, hash_offset,
720
+ // Returns a tuple of (minimum required malloc alignment,
721
721
// array_size), from the start of a mallocated array.
722
722
fn calculate_allocation ( hash_size : usize ,
723
723
hash_align : usize ,
724
724
pairs_size : usize ,
725
725
pairs_align : usize )
726
- -> ( usize , usize , usize , bool ) {
727
- let hash_offset = 0 ;
726
+ -> ( usize , usize , bool ) {
728
727
let ( _, end_of_pairs, oflo) = calculate_offsets ( hash_size, pairs_size, pairs_align) ;
729
728
730
729
let align = cmp:: max ( hash_align, pairs_align) ;
731
730
732
- ( align, hash_offset , end_of_pairs, oflo)
731
+ ( align, end_of_pairs, oflo)
733
732
}
734
733
735
734
#[ test]
736
735
fn test_offset_calculation ( ) {
737
- assert_eq ! ( calculate_allocation( 128 , 8 , 16 , 8 ) , ( 8 , 0 , 144 , false ) ) ;
738
- assert_eq ! ( calculate_allocation( 3 , 1 , 2 , 1 ) , ( 1 , 0 , 5 , false ) ) ;
739
- assert_eq ! ( calculate_allocation( 6 , 2 , 12 , 4 ) , ( 4 , 0 , 20 , false ) ) ;
736
+ assert_eq ! ( calculate_allocation( 128 , 8 , 16 , 8 ) , ( 8 , 144 , false ) ) ;
737
+ assert_eq ! ( calculate_allocation( 3 , 1 , 2 , 1 ) , ( 1 , 5 , false ) ) ;
738
+ assert_eq ! ( calculate_allocation( 6 , 2 , 12 , 4 ) , ( 4 , 20 , false ) ) ;
740
739
assert_eq ! ( calculate_offsets( 128 , 15 , 4 ) , ( 128 , 143 , false ) ) ;
741
740
assert_eq ! ( calculate_offsets( 3 , 2 , 4 ) , ( 4 , 6 , false ) ) ;
742
741
assert_eq ! ( calculate_offsets( 6 , 12 , 4 ) , ( 8 , 20 , false ) ) ;
@@ -768,10 +767,10 @@ impl<K, V> RawTable<K, V> {
768
767
// This is great in theory, but in practice getting the alignment
769
768
// right is a little subtle. Therefore, calculating offsets has been
770
769
// factored out into a different function.
771
- let ( alignment, hash_offset , size, oflo) = calculate_allocation ( hashes_size,
772
- align_of :: < HashUint > ( ) ,
773
- pairs_size,
774
- align_of :: < ( K , V ) > ( ) ) ;
770
+ let ( alignment, size, oflo) = calculate_allocation ( hashes_size,
771
+ align_of :: < HashUint > ( ) ,
772
+ pairs_size,
773
+ align_of :: < ( K , V ) > ( ) ) ;
775
774
assert ! ( !oflo, "capacity overflow" ) ;
776
775
777
776
// One check for overflow that covers calculation and rounding of size.
@@ -784,7 +783,7 @@ impl<K, V> RawTable<K, V> {
784
783
let buffer = Heap . alloc ( Layout :: from_size_align ( size, alignment) . unwrap ( ) )
785
784
. unwrap_or_else ( |e| Heap . oom ( e) ) ;
786
785
787
- let hashes = buffer. offset ( hash_offset as isize ) as * mut HashUint ;
786
+ let hashes = buffer as * mut HashUint ;
788
787
789
788
RawTable {
790
789
capacity_mask : capacity. wrapping_sub ( 1 ) ,
@@ -1157,6 +1156,7 @@ impl<K: Clone, V: Clone> Clone for RawTable<K, V> {
1157
1156
}
1158
1157
1159
1158
new_ht. size = self . size ( ) ;
1159
+ new_ht. set_tag ( self . tag ( ) ) ;
1160
1160
1161
1161
new_ht
1162
1162
}
@@ -1183,10 +1183,10 @@ unsafe impl<#[may_dangle] K, #[may_dangle] V> Drop for RawTable<K, V> {
1183
1183
1184
1184
let hashes_size = self . capacity ( ) * size_of :: < HashUint > ( ) ;
1185
1185
let pairs_size = self . capacity ( ) * size_of :: < ( K , V ) > ( ) ;
1186
- let ( align, _ , size, oflo) = calculate_allocation ( hashes_size,
1187
- align_of :: < HashUint > ( ) ,
1188
- pairs_size,
1189
- align_of :: < ( K , V ) > ( ) ) ;
1186
+ let ( align, size, oflo) = calculate_allocation ( hashes_size,
1187
+ align_of :: < HashUint > ( ) ,
1188
+ pairs_size,
1189
+ align_of :: < ( K , V ) > ( ) ) ;
1190
1190
1191
1191
debug_assert ! ( !oflo, "should be impossible" ) ;
1192
1192
0 commit comments