MCPcopy Create free account
hub / github.com/Lokathor/tinyvec / remove

Method remove

src/arrayvec.rs:743–759  ·  view source on GitHub ↗
(&mut self, index: usize)

Source from the content-addressed store, hash-verified

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.

Callers 5

nextMethod · 0.45
next_backMethod · 0.45
nextMethod · 0.45
next_backMethod · 0.45
ArrayVec_remove_invalidFunction · 0.45

Calls 2

deref_mutMethod · 0.45
lenMethod · 0.45

Tested by

no test coverage detected