@@ -134,7 +134,7 @@ impl<A: Array> ArrayVec<A> {
134134 /// let array = ArrayVec::from([1, 2, 3]);
135135 /// assert_eq!(array.capacity(), 3);
136136 /// ```
137- #[ inline]
137+ #[ inline( always ) ]
138138 pub fn capacity ( & self ) -> usize { A :: CAPACITY }
139139
140140 /// Return if the `ArrayVec` is completely filled.
@@ -235,14 +235,18 @@ impl<A: Array> ArrayVec<A> {
235235 ///
236236 /// assert_eq!(&array[..], &[1, 2]);
237237 /// ```
238- #[ inline]
239238 pub unsafe fn push_unchecked ( & mut self , element : A :: Item ) {
240239 let len = self . len ( ) ;
241240 debug_assert ! ( len < A :: CAPACITY ) ;
242- ptr:: write ( self . get_unchecked_mut ( len) , element) ;
241+ ptr:: write ( self . get_unchecked_ptr ( len) , element) ;
243242 self . set_len ( len + 1 ) ;
244243 }
245244
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+
246250 /// Insert `element` at position `index`.
247251 ///
248252 /// Shift up all elements after `index`.
@@ -300,7 +304,7 @@ impl<A: Array> ArrayVec<A> {
300304 unsafe { // infallible
301305 // The spot to put the new value
302306 {
303- let p: * mut _ = self . get_unchecked_mut ( index) ;
307+ let p: * mut _ = self . get_unchecked_ptr ( index) ;
304308 // Shift everything over to make space. (Duplicating the
305309 // `index`th element into two consecutive places.)
306310 ptr:: copy ( p, p. offset ( 1 ) , len - index) ;
@@ -334,7 +338,7 @@ impl<A: Array> ArrayVec<A> {
334338 unsafe {
335339 let new_len = self . len ( ) - 1 ;
336340 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) ) )
338342 }
339343 }
340344
@@ -507,7 +511,6 @@ impl<A: Array> ArrayVec<A> {
507511 ///
508512 /// This method uses *debug assertions* to check that `length` is
509513 /// not greater than the capacity.
510- #[ inline]
511514 pub unsafe fn set_len ( & mut self , length : usize ) {
512515 debug_assert ! ( length <= self . capacity( ) ) ;
513516 self . len = Index :: from ( length) ;
@@ -628,7 +631,8 @@ impl<A: Array> ArrayVec<A> {
628631 }
629632 }
630633
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." ]
632636 pub fn dispose ( mut self ) {
633637 self . clear ( ) ;
634638 mem:: forget ( self ) ;
@@ -754,15 +758,14 @@ pub struct IntoIter<A: Array> {
754758impl < A : Array > Iterator for IntoIter < A > {
755759 type Item = A :: Item ;
756760
757- #[ inline]
758761 fn next ( & mut self ) -> Option < A :: Item > {
759762 if self . index == self . v . len {
760763 None
761764 } else {
762765 unsafe {
763766 let index = self . index . to_usize ( ) ;
764767 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) ) )
766769 }
767770 }
768771 }
@@ -774,15 +777,14 @@ impl<A: Array> Iterator for IntoIter<A> {
774777}
775778
776779impl < A : Array > DoubleEndedIterator for IntoIter < A > {
777- #[ inline]
778780 fn next_back ( & mut self ) -> Option < A :: Item > {
779781 if self . index == self . v . len {
780782 None
781783 } else {
782784 unsafe {
783785 let new_len = self . v . len ( ) - 1 ;
784786 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) ) )
786788 }
787789 }
788790 }
@@ -798,7 +800,7 @@ impl<A: Array> Drop for IntoIter<A> {
798800 unsafe {
799801 self . v . set_len ( 0 ) ;
800802 let elements = slice:: from_raw_parts_mut (
801- self . v . get_unchecked_mut ( index) ,
803+ self . v . get_unchecked_ptr ( index) ,
802804 len - index) ;
803805 ptr:: drop_in_place ( elements) ;
804806 }
@@ -851,7 +853,6 @@ impl<'a, A: Array> Iterator for Drain<'a, A>
851853{
852854 type Item = A :: Item ;
853855
854- #[ inline]
855856 fn next ( & mut self ) -> Option < Self :: Item > {
856857 self . iter . next ( ) . map ( |elt|
857858 unsafe {
@@ -860,7 +861,6 @@ impl<'a, A: Array> Iterator for Drain<'a, A>
860861 )
861862 }
862863
863- #[ inline]
864864 fn size_hint ( & self ) -> ( usize , Option < usize > ) {
865865 self . iter . size_hint ( )
866866 }
@@ -869,7 +869,6 @@ impl<'a, A: Array> Iterator for Drain<'a, A>
869869impl < ' a , A : Array > DoubleEndedIterator for Drain < ' a , A >
870870 where A :: Item : ' a ,
871871{
872- #[ inline]
873872 fn next_back ( & mut self ) -> Option < Self :: Item > {
874873 self . iter . next_back ( ) . map ( |elt|
875874 unsafe {
@@ -1068,27 +1067,22 @@ impl<A: Array> Default for ArrayVec<A> {
10681067}
10691068
10701069impl < A : Array > PartialOrd for ArrayVec < A > where A :: Item : PartialOrd {
1071- #[ inline]
10721070 fn partial_cmp ( & self , other : & ArrayVec < A > ) -> Option < cmp:: Ordering > {
10731071 ( * * self ) . partial_cmp ( other)
10741072 }
10751073
1076- #[ inline]
10771074 fn lt ( & self , other : & Self ) -> bool {
10781075 ( * * self ) . lt ( other)
10791076 }
10801077
1081- #[ inline]
10821078 fn le ( & self , other : & Self ) -> bool {
10831079 ( * * self ) . le ( other)
10841080 }
10851081
1086- #[ inline]
10871082 fn ge ( & self , other : & Self ) -> bool {
10881083 ( * * self ) . ge ( other)
10891084 }
10901085
1091- #[ inline]
10921086 fn gt ( & self , other : & Self ) -> bool {
10931087 ( * * self ) . gt ( other)
10941088 }
0 commit comments