Skip to content

Commit 1dbab48

Browse files
committed
memory-based ascii illustration
1 parent 567cd52 commit 1dbab48

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

library/alloc/src/vec.rs

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2388,24 +2388,28 @@ impl<T> SpecExtend<T, IntoIter<T>> for Vec<T> {
23882388
// Avoid reallocation if we can use iterator's storage instead. This requires 1 memcpy and 0-1 memmove
23892389
// while reallocation would require 1 alloc, 1-2 memcpy, 1-2 free.
23902390
//
2391-
// A) non-empty self, partially consumed iterator
2391+
// ## non-empty self, partially consumed iterator
23922392
//
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---------------
23982396
//
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)
24002401
//
2401-
// | | | BBBB |
2402-
// | | |BBBB | into_vec_with_uninit_prefix
2403-
// |BBBB | -- *self = v
2402+
// ## empty self, partially consumed iterator
24042403
//
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)
24062412
//
2407-
// | | |BBBB |
2408-
// |BBBB | -- *self = v
24092413
if mem::size_of::<T>() > 0
24102414
&& self.capacity() - self.len() < iterator.len()
24112415
&& iterator.cap - iterator.len() >= self.len()

0 commit comments

Comments
 (0)