@@ -134,7 +134,7 @@ impl<A: Array> ArrayVec<A> {
134
134
/// let array = ArrayVec::from([1, 2, 3]);
135
135
/// assert_eq!(array.capacity(), 3);
136
136
/// ```
137
- #[ inline]
137
+ #[ inline( always ) ]
138
138
pub fn capacity ( & self ) -> usize { A :: CAPACITY }
139
139
140
140
/// Return if the `ArrayVec` is completely filled.
@@ -235,14 +235,18 @@ impl<A: Array> ArrayVec<A> {
235
235
///
236
236
/// assert_eq!(&array[..], &[1, 2]);
237
237
/// ```
238
- #[ inline]
239
238
pub unsafe fn push_unchecked ( & mut self , element : A :: Item ) {
240
239
let len = self . len ( ) ;
241
240
debug_assert ! ( len < A :: CAPACITY ) ;
242
- ptr:: write ( self . get_unchecked_mut ( len) , element) ;
241
+ ptr:: write ( self . get_unchecked_ptr ( len) , element) ;
243
242
self . set_len ( len + 1 ) ;
244
243
}
245
244
245
+ /// Get pointer to where element at `index` would be
246
+ unsafe fn get_unchecked_ptr ( & mut self , index : usize ) -> * mut A :: Item {
247
+ self . xs . ptr_mut ( ) . add ( index)
248
+ }
249
+
246
250
/// Insert `element` at position `index`.
247
251
///
248
252
/// Shift up all elements after `index`.
@@ -300,7 +304,7 @@ impl<A: Array> ArrayVec<A> {
300
304
unsafe { // infallible
301
305
// The spot to put the new value
302
306
{
303
- let p: * mut _ = self . get_unchecked_mut ( index) ;
307
+ let p: * mut _ = self . get_unchecked_ptr ( index) ;
304
308
// Shift everything over to make space. (Duplicating the
305
309
// `index`th element into two consecutive places.)
306
310
ptr:: copy ( p, p. offset ( 1 ) , len - index) ;
@@ -334,7 +338,7 @@ impl<A: Array> ArrayVec<A> {
334
338
unsafe {
335
339
let new_len = self . len ( ) - 1 ;
336
340
self . set_len ( new_len) ;
337
- Some ( ptr:: read ( self . get_unchecked_mut ( new_len) ) )
341
+ Some ( ptr:: read ( self . get_unchecked_ptr ( new_len) ) )
338
342
}
339
343
}
340
344
@@ -507,7 +511,6 @@ impl<A: Array> ArrayVec<A> {
507
511
///
508
512
/// This method uses *debug assertions* to check that `length` is
509
513
/// not greater than the capacity.
510
- #[ inline]
511
514
pub unsafe fn set_len ( & mut self , length : usize ) {
512
515
debug_assert ! ( length <= self . capacity( ) ) ;
513
516
self . len = Index :: from ( length) ;
@@ -628,7 +631,8 @@ impl<A: Array> ArrayVec<A> {
628
631
}
629
632
}
630
633
631
- /// Dispose of `self` without the overwriting that is needed in Drop.
634
+ /// Dispose of `self` (same as drop)
635
+ #[ deprecated="Use std::mem::drop instead, if at all needed." ]
632
636
pub fn dispose ( mut self ) {
633
637
self . clear ( ) ;
634
638
mem:: forget ( self ) ;
@@ -754,15 +758,14 @@ pub struct IntoIter<A: Array> {
754
758
impl < A : Array > Iterator for IntoIter < A > {
755
759
type Item = A :: Item ;
756
760
757
- #[ inline]
758
761
fn next ( & mut self ) -> Option < A :: Item > {
759
762
if self . index == self . v . len {
760
763
None
761
764
} else {
762
765
unsafe {
763
766
let index = self . index . to_usize ( ) ;
764
767
self . index = Index :: from ( index + 1 ) ;
765
- Some ( ptr:: read ( self . v . get_unchecked_mut ( index) ) )
768
+ Some ( ptr:: read ( self . v . get_unchecked_ptr ( index) ) )
766
769
}
767
770
}
768
771
}
@@ -774,15 +777,14 @@ impl<A: Array> Iterator for IntoIter<A> {
774
777
}
775
778
776
779
impl < A : Array > DoubleEndedIterator for IntoIter < A > {
777
- #[ inline]
778
780
fn next_back ( & mut self ) -> Option < A :: Item > {
779
781
if self . index == self . v . len {
780
782
None
781
783
} else {
782
784
unsafe {
783
785
let new_len = self . v . len ( ) - 1 ;
784
786
self . v . set_len ( new_len) ;
785
- Some ( ptr:: read ( self . v . get_unchecked_mut ( new_len) ) )
787
+ Some ( ptr:: read ( self . v . get_unchecked_ptr ( new_len) ) )
786
788
}
787
789
}
788
790
}
@@ -798,7 +800,7 @@ impl<A: Array> Drop for IntoIter<A> {
798
800
unsafe {
799
801
self . v . set_len ( 0 ) ;
800
802
let elements = slice:: from_raw_parts_mut (
801
- self . v . get_unchecked_mut ( index) ,
803
+ self . v . get_unchecked_ptr ( index) ,
802
804
len - index) ;
803
805
ptr:: drop_in_place ( elements) ;
804
806
}
@@ -851,7 +853,6 @@ impl<'a, A: Array> Iterator for Drain<'a, A>
851
853
{
852
854
type Item = A :: Item ;
853
855
854
- #[ inline]
855
856
fn next ( & mut self ) -> Option < Self :: Item > {
856
857
self . iter . next ( ) . map ( |elt|
857
858
unsafe {
@@ -860,7 +861,6 @@ impl<'a, A: Array> Iterator for Drain<'a, A>
860
861
)
861
862
}
862
863
863
- #[ inline]
864
864
fn size_hint ( & self ) -> ( usize , Option < usize > ) {
865
865
self . iter . size_hint ( )
866
866
}
@@ -869,7 +869,6 @@ impl<'a, A: Array> Iterator for Drain<'a, A>
869
869
impl < ' a , A : Array > DoubleEndedIterator for Drain < ' a , A >
870
870
where A :: Item : ' a ,
871
871
{
872
- #[ inline]
873
872
fn next_back ( & mut self ) -> Option < Self :: Item > {
874
873
self . iter . next_back ( ) . map ( |elt|
875
874
unsafe {
@@ -1068,27 +1067,22 @@ impl<A: Array> Default for ArrayVec<A> {
1068
1067
}
1069
1068
1070
1069
impl < A : Array > PartialOrd for ArrayVec < A > where A :: Item : PartialOrd {
1071
- #[ inline]
1072
1070
fn partial_cmp ( & self , other : & ArrayVec < A > ) -> Option < cmp:: Ordering > {
1073
1071
( * * self ) . partial_cmp ( other)
1074
1072
}
1075
1073
1076
- #[ inline]
1077
1074
fn lt ( & self , other : & Self ) -> bool {
1078
1075
( * * self ) . lt ( other)
1079
1076
}
1080
1077
1081
- #[ inline]
1082
1078
fn le ( & self , other : & Self ) -> bool {
1083
1079
( * * self ) . le ( other)
1084
1080
}
1085
1081
1086
- #[ inline]
1087
1082
fn ge ( & self , other : & Self ) -> bool {
1088
1083
( * * self ) . ge ( other)
1089
1084
}
1090
1085
1091
- #[ inline]
1092
1086
fn gt ( & self , other : & Self ) -> bool {
1093
1087
( * * self ) . gt ( other)
1094
1088
}
0 commit comments