@@ -2388,24 +2388,28 @@ impl<T> SpecExtend<T, IntoIter<T>> for Vec<T> {
2388
2388
// Avoid reallocation if we can use iterator's storage instead. This requires 1 memcpy and 0-1 memmove
2389
2389
// while reallocation would require 1 alloc, 1-2 memcpy, 1-2 free.
2390
2390
//
2391
- // A) non-empty self, partially consumed iterator
2391
+ // ## non-empty self, partially consumed iterator
2392
2392
//
2393
- // self iterator
2394
- // |AAAA | | BBB |
2395
- // |AAAA | | BBB | into_vec_with_uninit_prefix
2396
- // | | |AAAABBB | prepend
2397
- // |AAAABBB | -- *self = v
2393
+ // == step == == memory == == self == == iter / v ==
2394
+ // 0123456789abcdef0123456789abcdef
2395
+ // 0---------------1---------------
2398
2396
//
2399
- // B) empty self, partially consumed iterator
2397
+ // [initial] AAAA_-----__BBB___-------------- Vec(0x00, 4, 5) IntoIter(0x0a, 0x0c, 0x0f, 8)
2398
+ // into_vec AAAA_-----____BBB_-------------- Vec(0x00, 4, 5) Vec(0x0a, 7, 8)
2399
+ // prepend _____-----AAAABBB_-------------- Vec(0x00, 0, 5) Vec(0x0a, 7, 8)
2400
+ // *self = v ----------AAAABBB_-------------- Vec(0x0a, 7, 8)
2400
2401
//
2401
- // | | | BBBB |
2402
- // | | |BBBB | into_vec_with_uninit_prefix
2403
- // |BBBB | -- *self = v
2402
+ // ## empty self, partially consumed iterator
2404
2403
//
2405
- // C) empty self, pristine iterator
2404
+ // [initial] ____------__BBBB__-------------- Vec(0x00, 0, 4) IntoIter(0x0a, 0x0c, 0x10, 8)
2405
+ // into_vec ____------BBBB____-------------- Vec(0x00, 0, 4) Vec(0x0a, 4, 8)
2406
+ // *self = v ----------BBBB____-------------- Vec(0x0a, 4, 8)
2407
+ //
2408
+ // ## empty self, pristine iterator
2409
+ //
2410
+ // [initial] ----------BBBB____-------------- Vec(0x00, 0, 0) IntoIter(0x0a, 0x0a, 0x0e, 8)
2411
+ // *self = v ----------BBBB____-------------- Vec(0x0a, 4, 8)
2406
2412
//
2407
- // | | |BBBB |
2408
- // |BBBB | -- *self = v
2409
2413
if mem:: size_of :: < T > ( ) > 0
2410
2414
&& self . capacity ( ) - self . len ( ) < iterator. len ( )
2411
2415
&& iterator. cap - iterator. len ( ) >= self . len ( )
0 commit comments