MCPcopy Index your code
hub / github.com/RustPython/RustPython / extend

Method extend

crates/common/src/boxvec.rs:539–570  ·  view source on GitHub ↗
(&mut self, iter: I)

Source from the content-addressed store, hash-verified

537/// occurs if there are more iterator elements.
538impl<T> Extend<T> for BoxVec<T> {
539 fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I) {
540 let take = self.capacity() - self.len();
541 unsafe {
542 let len = self.len();
543 let mut ptr = raw_ptr_add(self.as_mut_ptr(), len);
544 let end_ptr = raw_ptr_add(ptr, take);
545 // Keep the length in a separate variable, write it back on scope
546 // exit. To help the compiler with alias analysis and stuff.
547 // We update the length to handle panic in the iteration of the
548 // user's iterator, without dropping any elements on the floor.
549 let mut guard = ScopeExitGuard {
550 value: &mut self.len,
551 data: len,
552 f: move |&len, self_len| {
553 **self_len = len;
554 },
555 };
556 let mut iter = iter.into_iter();
557 loop {
558 if core::ptr::eq(ptr, end_ptr) {
559 break;
560 }
561 if let Some(elt) = iter.next() {
562 raw_ptr_write(ptr, elt);
563 ptr = raw_ptr_add(ptr, 1);
564 guard.data += 1;
565 } else {
566 break;
567 }
568 }
569 }
570 }
571}
572
573/// Rawptr add but uses arithmetic distance for ZST

Callers 7

cloneMethod · 0.45
clone_fromMethod · 0.45
zfillFunction · 0.45
encodeFunction · 0.45
concatMethod · 0.45
parseMethod · 0.45

Calls 8

raw_ptr_addFunction · 0.85
raw_ptr_writeFunction · 0.85
as_mut_ptrMethod · 0.80
eqFunction · 0.50
capacityMethod · 0.45
lenMethod · 0.45
into_iterMethod · 0.45
nextMethod · 0.45

Tested by

no test coverage detected