(
&mut self, iter: I,
)
| 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 | /// |
no test coverage detected