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

Method fill

src/arrayvec.rs:513–530  ·  view source on GitHub ↗
(
    &mut self, iter: I,
  )

Source from the content-addressed store, hash-verified

511 /// ```
512 #[inline]
513 pub fn fill<I: IntoIterator<Item = A::Item>>(
514 &mut self, iter: I,
515 ) -> I::IntoIter {
516 // If this is written as a call to push for each element in iter, the
517 // compiler emits code that updates the length for every element. The
518 // additional complexity from that length update is worth nearly 2x in
519 // the runtime of this function.
520 let mut iter = iter.into_iter();
521 let mut pushed = 0;
522 let to_take = self.capacity() - self.len();
523 let target = &mut self.data.as_slice_mut()[self.len as usize..];
524 for element in iter.by_ref().take(to_take) {
525 target[pushed] = element;
526 pushed += 1;
527 }
528 self.len += pushed as u16;
529 iter
530 }
531
532 /// Wraps up an array and uses the given length as the initial length.
533 ///

Callers 2

shrink_to_fitMethod · 0.45
extendMethod · 0.45

Calls 4

into_iterMethod · 0.45
capacityMethod · 0.45
lenMethod · 0.45
as_slice_mutMethod · 0.45

Tested by

no test coverage detected