| 741 | /// ``` |
| 742 | #[inline] |
| 743 | pub fn remove(&mut self, index: usize) -> A::Item { |
| 744 | let targets: &mut [A::Item] = &mut self.deref_mut()[index..]; |
| 745 | let item = core::mem::take(&mut targets[0]); |
| 746 | |
| 747 | // A previous implementation used rotate_left |
| 748 | // rotate_right and rotate_left generate a huge amount of code and fail to |
| 749 | // inline; calling them here incurs the cost of all the cases they |
| 750 | // handle even though we're rotating a usually-small array by a constant |
| 751 | // 1 offset. This swap-based implementation benchmarks much better for |
| 752 | // small array lengths in particular. |
| 753 | |
| 754 | for i in 0..targets.len() - 1 { |
| 755 | targets.swap(i, i + 1); |
| 756 | } |
| 757 | self.len -= 1; |
| 758 | item |
| 759 | } |
| 760 | |
| 761 | /// As [`resize_with`](ArrayVec::resize_with) |
| 762 | /// and it clones the value as the closure. |