@@ -256,7 +256,7 @@ impl<'a, T: 'a + Array> Drop for Drain<'a, T> {
256
256
#[ cfg( feature = "union" ) ]
257
257
union SmallVecData < A : Array > {
258
258
inline : MaybeUninit < A > ,
259
- heap : ( NonNull < A :: Item > , usize ) ,
259
+ heap : ( * mut A :: Item , usize ) ,
260
260
}
261
261
262
262
#[ cfg( feature = "union" ) ]
@@ -279,24 +279,22 @@ impl<A: Array> SmallVecData<A> {
279
279
}
280
280
#[ inline]
281
281
unsafe fn heap ( & self ) -> ( * mut A :: Item , usize ) {
282
- ( self . heap . 0 . as_ptr ( ) , self . heap . 1 )
282
+ self . heap
283
283
}
284
284
#[ inline]
285
- unsafe fn heap_mut ( & mut self ) -> ( * mut A :: Item , & mut usize ) {
286
- ( self . heap . 0 . as_ptr ( ) , & mut self . heap . 1 )
285
+ unsafe fn heap_mut ( & mut self ) -> & mut ( * mut A :: Item , usize ) {
286
+ & mut self . heap
287
287
}
288
288
#[ inline]
289
289
fn from_heap ( ptr : * mut A :: Item , len : usize ) -> SmallVecData < A > {
290
- SmallVecData {
291
- heap : ( NonNull :: new ( ptr) . unwrap ( ) , len) ,
292
- }
290
+ SmallVecData { heap : ( ptr, len) }
293
291
}
294
292
}
295
293
296
294
#[ cfg( not( feature = "union" ) ) ]
297
295
enum SmallVecData < A : Array > {
298
296
Inline ( MaybeUninit < A > ) ,
299
- Heap ( ( NonNull < A :: Item > , usize ) ) ,
297
+ Heap ( ( * mut A :: Item , usize ) ) ,
300
298
}
301
299
302
300
#[ cfg( not( feature = "union" ) ) ]
@@ -329,20 +327,20 @@ impl<A: Array> SmallVecData<A> {
329
327
#[ inline]
330
328
unsafe fn heap ( & self ) -> ( * mut A :: Item , usize ) {
331
329
match self {
332
- SmallVecData :: Heap ( data) => ( data. 0 . as_ptr ( ) , data . 1 ) ,
330
+ SmallVecData :: Heap ( data) => * data,
333
331
_ => debug_unreachable ! ( ) ,
334
332
}
335
333
}
336
334
#[ inline]
337
- unsafe fn heap_mut ( & mut self ) -> ( * mut A :: Item , & mut usize ) {
335
+ unsafe fn heap_mut ( & mut self ) -> & mut ( * mut A :: Item , usize ) {
338
336
match self {
339
- SmallVecData :: Heap ( data) => ( data. 0 . as_ptr ( ) , & mut data . 1 ) ,
337
+ SmallVecData :: Heap ( data) => data,
340
338
_ => debug_unreachable ! ( ) ,
341
339
}
342
340
}
343
341
#[ inline]
344
342
fn from_heap ( ptr : * mut A :: Item , len : usize ) -> SmallVecData < A > {
345
- SmallVecData :: Heap ( ( NonNull :: new ( ptr) . unwrap ( ) , len) )
343
+ SmallVecData :: Heap ( ( ptr, len) )
346
344
}
347
345
}
348
346
@@ -569,7 +567,7 @@ impl<A: Array> SmallVec<A> {
569
567
fn triple_mut ( & mut self ) -> ( * mut A :: Item , & mut usize , usize ) {
570
568
unsafe {
571
569
if self . spilled ( ) {
572
- let ( ptr, len_ptr) = self . data . heap_mut ( ) ;
570
+ let & mut ( ptr, ref mut len_ptr) = self . data . heap_mut ( ) ;
573
571
( ptr, len_ptr, self . capacity )
574
572
} else {
575
573
( self . data . inline_mut ( ) , & mut self . capacity , A :: size ( ) )
@@ -641,7 +639,7 @@ impl<A: Array> SmallVec<A> {
641
639
}
642
640
let ( ptr, len_ptr, _) = self . triple_mut ( ) ;
643
641
* len_ptr = len + 1 ;
644
- ptr:: write ( ptr. offset ( len as isize ) , value) ;
642
+ ptr:: write ( ptr. add ( len) , value) ;
645
643
}
646
644
}
647
645
@@ -655,7 +653,7 @@ impl<A: Array> SmallVec<A> {
655
653
}
656
654
let last_index = * len_ptr - 1 ;
657
655
* len_ptr = last_index;
658
- Some ( ptr:: read ( ptr. offset ( last_index as isize ) ) )
656
+ Some ( ptr:: read ( ptr. add ( last_index) ) )
659
657
}
660
658
}
661
659
@@ -761,7 +759,7 @@ impl<A: Array> SmallVec<A> {
761
759
while len < * len_ptr {
762
760
let last_index = * len_ptr - 1 ;
763
761
* len_ptr = last_index;
764
- ptr:: drop_in_place ( ptr. offset ( last_index as isize ) ) ;
762
+ ptr:: drop_in_place ( ptr. add ( last_index) ) ;
765
763
}
766
764
}
767
765
}
@@ -809,9 +807,9 @@ impl<A: Array> SmallVec<A> {
809
807
let len = * len_ptr;
810
808
assert ! ( index < len) ;
811
809
* len_ptr = len - 1 ;
812
- ptr = ptr. offset ( index as isize ) ;
810
+ ptr = ptr. add ( index) ;
813
811
let item = ptr:: read ( ptr) ;
814
- ptr:: copy ( ptr. offset ( 1 ) , ptr, len - index - 1 ) ;
812
+ ptr:: copy ( ptr. add ( 1 ) , ptr, len - index - 1 ) ;
815
813
item
816
814
}
817
815
}
@@ -827,8 +825,8 @@ impl<A: Array> SmallVec<A> {
827
825
let len = * len_ptr;
828
826
assert ! ( index <= len) ;
829
827
* len_ptr = len + 1 ;
830
- ptr = ptr. offset ( index as isize ) ;
831
- ptr:: copy ( ptr, ptr. offset ( 1 ) , len - index) ;
828
+ ptr = ptr. add ( index) ;
829
+ ptr:: copy ( ptr, ptr. add ( 1 ) , len - index) ;
832
830
ptr:: write ( ptr, element) ;
833
831
}
834
832
}
@@ -849,32 +847,32 @@ impl<A: Array> SmallVec<A> {
849
847
unsafe {
850
848
let old_len = self . len ( ) ;
851
849
assert ! ( index <= old_len) ;
852
- let mut ptr = self . as_mut_ptr ( ) . offset ( index as isize ) ;
850
+ let mut ptr = self . as_mut_ptr ( ) . add ( index) ;
853
851
854
852
// Move the trailing elements.
855
- ptr:: copy ( ptr, ptr. offset ( lower_size_bound as isize ) , old_len - index) ;
853
+ ptr:: copy ( ptr, ptr. add ( lower_size_bound) , old_len - index) ;
856
854
857
855
// In case the iterator panics, don't double-drop the items we just copied above.
858
856
self . set_len ( index) ;
859
857
860
858
let mut num_added = 0 ;
861
859
for element in iter {
862
- let mut cur = ptr. offset ( num_added as isize ) ;
860
+ let mut cur = ptr. add ( num_added) ;
863
861
if num_added >= lower_size_bound {
864
862
// Iterator provided more elements than the hint. Move trailing items again.
865
863
self . reserve ( 1 ) ;
866
- ptr = self . as_mut_ptr ( ) . offset ( index as isize ) ;
867
- cur = ptr. offset ( num_added as isize ) ;
868
- ptr:: copy ( cur, cur. offset ( 1 ) , old_len - index) ;
864
+ ptr = self . as_mut_ptr ( ) . add ( index) ;
865
+ cur = ptr. add ( num_added) ;
866
+ ptr:: copy ( cur, cur. add ( 1 ) , old_len - index) ;
869
867
}
870
868
ptr:: write ( cur, element) ;
871
869
num_added += 1 ;
872
870
}
873
871
if num_added < lower_size_bound {
874
872
// Iterator provided fewer elements than the hint
875
873
ptr:: copy (
876
- ptr. offset ( lower_size_bound as isize ) ,
877
- ptr. offset ( num_added as isize ) ,
874
+ ptr. add ( lower_size_bound) ,
875
+ ptr. add ( num_added) ,
878
876
old_len - index,
879
877
) ;
880
878
}
@@ -957,11 +955,11 @@ impl<A: Array> SmallVec<A> {
957
955
958
956
unsafe {
959
957
for r in 1 ..len {
960
- let p_r = ptr. offset ( r as isize ) ;
961
- let p_wm1 = ptr. offset ( ( w - 1 ) as isize ) ;
958
+ let p_r = ptr. add ( r ) ;
959
+ let p_wm1 = ptr. add ( w - 1 ) ;
962
960
if !same_bucket ( & mut * p_r, & mut * p_wm1) {
963
961
if r != w {
964
- let p_w = p_wm1. offset ( 1 ) ;
962
+ let p_w = p_wm1. add ( 1 ) ;
965
963
mem:: swap ( & mut * p_r, & mut * p_w) ;
966
964
}
967
965
w += 1 ;
@@ -1039,8 +1037,8 @@ impl<A: Array> SmallVec<A> {
1039
1037
/// // writing into the old `SmallVec`'s inline storage on the
1040
1038
/// // stack.
1041
1039
/// assert!(spilled);
1042
- /// for i in 0..len as isize {
1043
- /// ptr::write(p.offset (i), 4 + i);
1040
+ /// for i in 0..len {
1041
+ /// ptr::write(p.add (i), 4 + i);
1044
1042
/// }
1045
1043
///
1046
1044
/// // Put everything back together into a SmallVec with a different
@@ -1103,8 +1101,8 @@ where
1103
1101
1104
1102
unsafe {
1105
1103
let slice_ptr = slice. as_ptr ( ) ;
1106
- let ptr = self . as_mut_ptr ( ) . offset ( index as isize ) ;
1107
- ptr:: copy ( ptr, ptr. offset ( slice. len ( ) as isize ) , len - index) ;
1104
+ let ptr = self . as_mut_ptr ( ) . add ( index) ;
1105
+ ptr:: copy ( ptr, ptr. add ( slice. len ( ) ) , len - index) ;
1108
1106
ptr:: copy_nonoverlapping ( slice_ptr, ptr, slice. len ( ) ) ;
1109
1107
self . set_len ( len + slice. len ( ) ) ;
1110
1108
}
@@ -1156,8 +1154,8 @@ where
1156
1154
let ( ptr, len_ptr, _) = v. triple_mut ( ) ;
1157
1155
let mut local_len = SetLenOnDrop :: new ( len_ptr) ;
1158
1156
1159
- for i in 0 ..n as isize {
1160
- :: core:: ptr:: write ( ptr. offset ( i) , elem. clone ( ) ) ;
1157
+ for i in 0 ..n {
1158
+ :: core:: ptr:: write ( ptr. add ( i) , elem. clone ( ) ) ;
1161
1159
local_len. increment_len ( 1 ) ;
1162
1160
}
1163
1161
}
@@ -1318,7 +1316,7 @@ where
1318
1316
#[ cfg( not( feature = "specialization" ) ) ]
1319
1317
#[ inline]
1320
1318
fn from ( slice : & ' a [ A :: Item ] ) -> SmallVec < A > {
1321
- slice. into_iter ( ) . cloned ( ) . collect ( )
1319
+ slice. iter ( ) . cloned ( ) . collect ( )
1322
1320
}
1323
1321
1324
1322
#[ cfg( feature = "specialization" ) ]
@@ -1384,7 +1382,7 @@ impl<A: Array> Extend<A::Item> for SmallVec<A> {
1384
1382
let mut len = SetLenOnDrop :: new ( len_ptr) ;
1385
1383
while len. get ( ) < cap {
1386
1384
if let Some ( out) = iter. next ( ) {
1387
- ptr:: write ( ptr. offset ( len. get ( ) as isize ) , out) ;
1385
+ ptr:: write ( ptr. add ( len. get ( ) ) , out) ;
1388
1386
len. increment_len ( 1 ) ;
1389
1387
} else {
1390
1388
return ;
@@ -1463,10 +1461,6 @@ where
1463
1461
fn eq ( & self , other : & SmallVec < B > ) -> bool {
1464
1462
self [ ..] == other[ ..]
1465
1463
}
1466
- #[ inline]
1467
- fn ne ( & self , other : & SmallVec < B > ) -> bool {
1468
- self [ ..] != other[ ..]
1469
- }
1470
1464
}
1471
1465
1472
1466
impl < A : Array > Eq for SmallVec < A > where A :: Item : Eq { }
@@ -1528,9 +1522,9 @@ impl<A: Array> Iterator for IntoIter<A> {
1528
1522
None
1529
1523
} else {
1530
1524
unsafe {
1531
- let current = self . current as isize ;
1525
+ let current = self . current ;
1532
1526
self . current += 1 ;
1533
- Some ( ptr:: read ( self . data . as_ptr ( ) . offset ( current) ) )
1527
+ Some ( ptr:: read ( self . data . as_ptr ( ) . add ( current) ) )
1534
1528
}
1535
1529
}
1536
1530
}
@@ -1550,7 +1544,7 @@ impl<A: Array> DoubleEndedIterator for IntoIter<A> {
1550
1544
} else {
1551
1545
unsafe {
1552
1546
self . end -= 1 ;
1553
- Some ( ptr:: read ( self . data . as_ptr ( ) . offset ( self . end as isize ) ) )
1547
+ Some ( ptr:: read ( self . data . as_ptr ( ) . add ( self . end ) ) )
1554
1548
}
1555
1549
}
1556
1550
}
@@ -1613,7 +1607,7 @@ impl<'a> SetLenOnDrop<'a> {
1613
1607
fn new ( len : & ' a mut usize ) -> Self {
1614
1608
SetLenOnDrop {
1615
1609
local_len : * len,
1616
- len : len ,
1610
+ len,
1617
1611
}
1618
1612
}
1619
1613
@@ -1649,7 +1643,7 @@ macro_rules! impl_array(
1649
1643
impl_array ! (
1650
1644
0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 , 13 , 14 , 15 , 16 , 20 , 24 , 32 , 36 , 0x40 , 0x60 , 0x80 ,
1651
1645
0x100 , 0x200 , 0x400 , 0x600 , 0x800 , 0x1000 , 0x2000 , 0x4000 , 0x6000 , 0x8000 , 0x10000 , 0x20000 ,
1652
- 0x40000 , 0x60000 , 0x80000 , 0x100000
1646
+ 0x40000 , 0x60000 , 0x80000 , 0x10_0000
1653
1647
) ;
1654
1648
1655
1649
#[ cfg( test) ]
0 commit comments