@@ -118,29 +118,15 @@ impl<I: Idx, T> IndexSlice<I, T> {
118
118
/// Panics if `a == b`.
119
119
#[ inline]
120
120
pub fn pick2_mut ( & mut self , a : I , b : I ) -> ( & mut T , & mut T ) {
121
- let ( ai, bi) = ( a. index ( ) , b. index ( ) ) ;
122
- assert ! ( ai != bi) ;
123
-
124
- if ai < bi {
125
- let ( c1, c2) = self . raw . split_at_mut ( bi) ;
126
- ( & mut c1[ ai] , & mut c2[ 0 ] )
127
- } else {
128
- let ( c2, c1) = self . pick2_mut ( b, a) ;
129
- ( c1, c2)
130
- }
121
+ self . raw . get_disjoint_mut ( [ a. index ( ) , b. index ( ) ] ) . unwrap ( )
131
122
}
132
123
133
124
/// Returns mutable references to three distinct elements.
134
125
///
135
126
/// Panics if the elements are not distinct.
136
127
#[ inline]
137
128
pub fn pick3_mut ( & mut self , a : I , b : I , c : I ) -> ( & mut T , & mut T , & mut T ) {
138
- let ( ai, bi, ci) = ( a. index ( ) , b. index ( ) , c. index ( ) ) ;
139
- assert ! ( ai != bi && bi != ci && ci != ai) ;
140
- let len = self . raw . len ( ) ;
141
- assert ! ( ai < len && bi < len && ci < len) ;
142
- let ptr = self . raw . as_mut_ptr ( ) ;
143
- unsafe { ( & mut * ptr. add ( ai) , & mut * ptr. add ( bi) , & mut * ptr. add ( ci) ) }
129
+ self . raw . get_disjoint_mut ( [ a. index ( ) , b. index ( ) , c. index ( ) ] ) . unwrap ( )
144
130
}
145
131
146
132
#[ inline]
0 commit comments