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

Method extendleft

crates/vm/src/stdlib/_collections.rs:143–163  ·  view source on GitHub ↗
(&self, iter: PyObjectRef, vm: &VirtualMachine)

Source from the content-addressed store, hash-verified

141
142 #[pymethod]
143 fn extendleft(&self, iter: PyObjectRef, vm: &VirtualMachine) -> PyResult<()> {
144 let max_len = self.maxlen;
145 let mut elements: Vec<PyObjectRef> = iter.try_to_value(vm)?;
146 elements.reverse();
147
148 if let Some(max_len) = max_len {
149 if max_len > elements.len() {
150 let mut deque = self.borrow_deque_mut();
151 let truncate_until = max_len - elements.len();
152 deque.truncate(truncate_until);
153 } else {
154 self.borrow_deque_mut().clear();
155 elements.truncate(max_len);
156 }
157 }
158 let mut created = VecDeque::from(elements);
159 let mut borrowed = self.borrow_deque_mut();
160 created.append(&mut borrowed);
161 core::mem::swap(&mut created, &mut borrowed);
162 Ok(())
163 }
164
165 #[pymethod]
166 fn index(

Callers 3

test_maxlenMethod · 0.80
test_maxlen_zeroMethod · 0.80
test_extendleftMethod · 0.80

Calls 7

try_to_valueMethod · 0.80
borrow_deque_mutMethod · 0.80
reverseMethod · 0.45
lenMethod · 0.45
truncateMethod · 0.45
clearMethod · 0.45
appendMethod · 0.45

Tested by 3

test_maxlenMethod · 0.64
test_maxlen_zeroMethod · 0.64
test_extendleftMethod · 0.64