@@ -1469,6 +1469,8 @@ impl<T> VecDeque<T> {
1469
1469
1470
1470
#[ inline]
1471
1471
fn is_contiguous ( & self ) -> bool {
1472
+ // FIXME: Should we consider `head == 0` to mean
1473
+ // that `self` is contiguous?
1472
1474
self . tail <= self . head
1473
1475
}
1474
1476
@@ -2198,7 +2200,7 @@ impl<T> VecDeque<T> {
2198
2200
if self . is_contiguous ( ) {
2199
2201
let tail = self . tail ;
2200
2202
let head = self . head ;
2201
- return unsafe { & mut self . buffer_as_mut_slice ( ) [ tail..head ] } ;
2203
+ return unsafe { RingSlices :: ring_slices ( self . buffer_as_mut_slice ( ) , head , tail) . 0 } ;
2202
2204
}
2203
2205
2204
2206
let buf = self . buf . ptr ( ) ;
@@ -2224,7 +2226,13 @@ impl<T> VecDeque<T> {
2224
2226
self . tail = 0 ;
2225
2227
self . head = len;
2226
2228
}
2227
- } else if free >= self . head {
2229
+ } else if free > self . head {
2230
+ // FIXME: We currently do not consider ....ABCDEFGH
2231
+ // to be contiguous because `head` would be `0` in this
2232
+ // case. While we probably want to change this it
2233
+ // isn't trivial as a few places expect `is_contiguous`
2234
+ // to mean that we can just slice using `buf[tail..head]`.
2235
+
2228
2236
// there is enough free space to copy the head in one go,
2229
2237
// this means that we first shift the tail forwards, and then
2230
2238
// copy the head to the correct position.
@@ -2238,7 +2246,7 @@ impl<T> VecDeque<T> {
2238
2246
// ...ABCDEFGH.
2239
2247
2240
2248
self . tail = self . head ;
2241
- self . head = self . tail + len;
2249
+ self . head = self . wrap_add ( self . tail , len) ;
2242
2250
}
2243
2251
} else {
2244
2252
// free is smaller than both head and tail,
@@ -2278,7 +2286,7 @@ impl<T> VecDeque<T> {
2278
2286
2279
2287
let tail = self . tail ;
2280
2288
let head = self . head ;
2281
- unsafe { & mut self . buffer_as_mut_slice ( ) [ tail..head ] }
2289
+ unsafe { RingSlices :: ring_slices ( self . buffer_as_mut_slice ( ) , head , tail) . 0 }
2282
2290
}
2283
2291
2284
2292
/// Rotates the double-ended queue `mid` places to the left.
@@ -2839,7 +2847,7 @@ impl<T> From<VecDeque<T>> for Vec<T> {
2839
2847
let len = other. len ( ) ;
2840
2848
let cap = other. cap ( ) ;
2841
2849
2842
- if other. head != 0 {
2850
+ if other. tail != 0 {
2843
2851
ptr:: copy ( buf. add ( other. tail ) , buf, len) ;
2844
2852
}
2845
2853
Vec :: from_raw_parts ( buf, len, cap)
0 commit comments