Removes the last element from the list.
(&mut self, len: usize, pool: &mut ListPool<T>)
| 546 | |
| 547 | /// Removes the last element from the list. |
| 548 | fn remove_last(&mut self, len: usize, pool: &mut ListPool<T>) { |
| 549 | // Check if we deleted the last element. |
| 550 | if len == 1 { |
| 551 | self.clear(pool); |
| 552 | return; |
| 553 | } |
| 554 | |
| 555 | // Do we need to reallocate to a smaller size class? |
| 556 | let mut block = self.index as usize - 1; |
| 557 | if is_sclass_min_length(len) { |
| 558 | let sclass = sclass_for_length(len); |
| 559 | block = pool.realloc(block, sclass, sclass - 1, len); |
| 560 | self.index = (block + 1) as u32; |
| 561 | } |
| 562 | |
| 563 | // Finally adjust the length. |
| 564 | pool.data[block] = T::new(len - 1); |
| 565 | } |
| 566 | |
| 567 | /// Removes the element at position `index` from the list. Potentially linear complexity. |
| 568 | pub fn remove(&mut self, index: usize, pool: &mut ListPool<T>) { |
no test coverage detected