File tree Expand file tree Collapse file tree 1 file changed +20
-1
lines changed Expand file tree Collapse file tree 1 file changed +20
-1
lines changed Original file line number Diff line number Diff line change @@ -2386,7 +2386,26 @@ where
2386
2386
impl < T > SpecExtend < T , IntoIter < T > > for Vec < T > {
2387
2387
fn spec_extend ( & mut self , iterator : IntoIter < T > ) {
2388
2388
// Avoid reallocation if we can use iterator's storage instead. This requires 1 memcpy and 0-1 memmove
2389
- // while reallocation would require 1 alloc, 1-2 memcpy, 1-2 free
2389
+ // while reallocation would require 1 alloc, 1-2 memcpy, 1-2 free.
2390
+ //
2391
+ // A) non-empty self, partially consumed iterator
2392
+ //
2393
+ // self iterator
2394
+ // |AAAA | | BBB |
2395
+ // |AAAA | | BBB | into_vec_with_uninit_prefix
2396
+ // | | |AAAABBB | prepend
2397
+ // |AAAABBB | -- *self = v
2398
+ //
2399
+ // B) empty self, partially consumed iterator
2400
+ //
2401
+ // | | | BBBB |
2402
+ // | | |BBBB | into_vec_with_uninit_prefix
2403
+ // |BBBB | -- *self = v
2404
+ //
2405
+ // C) empty self, pristine iterator
2406
+ //
2407
+ // | | |BBBB |
2408
+ // |BBBB | -- *self = v
2390
2409
if mem:: size_of :: < T > ( ) > 0
2391
2410
&& self . capacity ( ) - self . len ( ) < iterator. len ( )
2392
2411
&& iterator. cap - iterator. len ( ) >= self . len ( )
You can’t perform that action at this time.
0 commit comments