Grow list by adding `count` reserved-value elements at the end. Returns a mutable slice representing the whole list.
(&'a mut self, count: usize, pool: &'a mut ListPool<T>)
| 421 | /// |
| 422 | /// Returns a mutable slice representing the whole list. |
| 423 | fn grow<'a>(&'a mut self, count: usize, pool: &'a mut ListPool<T>) -> &'a mut [T] { |
| 424 | let idx = self.index as usize; |
| 425 | let new_len; |
| 426 | let block; |
| 427 | match pool.len_of(self) { |
| 428 | None => { |
| 429 | // This is an empty list. Allocate a block. |
| 430 | debug_assert_eq!(idx, 0, "Invalid pool"); |
| 431 | if count == 0 { |
| 432 | return &mut []; |
| 433 | } |
| 434 | new_len = count; |
| 435 | block = pool.alloc(sclass_for_length(new_len)); |
| 436 | self.index = (block + 1) as u32; |
| 437 | } |
| 438 | Some(len) => { |
| 439 | // Do we need to reallocate? |
| 440 | let sclass = sclass_for_length(len); |
| 441 | new_len = len + count; |
| 442 | let new_sclass = sclass_for_length(new_len); |
| 443 | if new_sclass != sclass { |
| 444 | block = pool.realloc(idx - 1, sclass, new_sclass, len + 1); |
| 445 | self.index = (block + 1) as u32; |
| 446 | } else { |
| 447 | block = idx - 1; |
| 448 | } |
| 449 | } |
| 450 | } |
| 451 | pool.data[block] = T::new(new_len); |
| 452 | &mut pool.data[block + 1..block + 1 + new_len] |
| 453 | } |
| 454 | |
| 455 | /// Constructs a list from an iterator. |
| 456 | pub fn from_iter<I>(elements: I, pool: &mut ListPool<T>) -> Self |