@@ -76,6 +76,16 @@ pub trait ImmutableVector<'a, T> {
76
76
* Fails when `end` points outside the bounds of self.
77
77
*/
78
78
fn slice_to ( & self , end : uint ) -> & ' a [ T ] ;
79
+
80
+ /// Divides one slice into two at an index.
81
+ ///
82
+ /// The first will contain all indices from `[0, mid)` (excluding
83
+ /// the index `mid` itself) and the second will contain all
84
+ /// indices from `[mid, len)` (excluding the index `len` itself).
85
+ ///
86
+ /// Fails if `mid > len`.
87
+ fn split_at ( & self , mid : uint ) -> ( & ' a [ T ] , & ' a [ T ] ) ;
88
+
79
89
/// Returns an iterator over the vector
80
90
fn iter ( self ) -> Items < ' a , T > ;
81
91
/// Returns an iterator over the subslices of the vector which are
@@ -247,6 +257,11 @@ impl<'a,T> ImmutableVector<'a, T> for &'a [T] {
247
257
self . slice( 0 , end)
248
258
}
249
259
260
+ #[ inline]
261
+ fn split_at ( & self , mid : uint ) -> ( & ' a [ T ] , & ' a [ T ] ) {
262
+ ( self . slice( 0 , mid) , self . slice( mid, self . len( ) ) )
263
+ }
264
+
250
265
#[ inline]
251
266
fn iter ( self ) -> Items < ' a , T > {
252
267
unsafe {
@@ -1192,8 +1207,7 @@ impl<'a, T> Iterator<&'a [T]> for Chunks<'a, T> {
1192
1207
None
1193
1208
} else {
1194
1209
let chunksz = cmp:: min ( self . v . len ( ) , self . size ) ;
1195
- let ( fst, snd) = ( self . v . slice_to ( chunksz) ,
1196
- self . v . slice_from ( chunksz) ) ;
1210
+ let ( fst, snd) = self . v . split_at ( chunksz) ;
1197
1211
self . v = snd;
1198
1212
Some ( fst)
1199
1213
}
@@ -1219,8 +1233,7 @@ impl<'a, T> DoubleEndedIterator<&'a [T]> for Chunks<'a, T> {
1219
1233
} else {
1220
1234
let remainder = self . v . len ( ) % self . size ;
1221
1235
let chunksz = if remainder != 0 { remainder } else { self . size } ;
1222
- let ( fst, snd) = ( self . v . slice_to ( self . v . len ( ) - chunksz) ,
1223
- self . v . slice_from ( self . v . len ( ) - chunksz) ) ;
1236
+ let ( fst, snd) = self . v . split_at ( self . v . len ( ) - chunksz) ;
1224
1237
self . v = fst;
1225
1238
Some ( snd)
1226
1239
}
0 commit comments