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

Method push_front

crates/common/src/linked_list.rs:154–182  ·  view source on GitHub ↗

Adds an element first in the list.

(&mut self, val: L::Handle)

Source from the content-addressed store, hash-verified

152impl<L: Link> LinkedList<L, L::Target> {
153 /// Adds an element first in the list.
154 pub fn push_front(&mut self, val: L::Handle) {
155 // The value should not be dropped, it is being inserted into the list
156 let val = ManuallyDrop::new(val);
157 let ptr = L::as_raw(&val);
158 assert_ne!(self.head, Some(ptr));
159 unsafe {
160 // Verify the node is not already in a list (pointers must be clean)
161 debug_assert!(
162 L::pointers(ptr).as_ref().get_prev().is_none(),
163 "push_front: node already has prev pointer (double-insert?)"
164 );
165 debug_assert!(
166 L::pointers(ptr).as_ref().get_next().is_none(),
167 "push_front: node already has next pointer (double-insert?)"
168 );
169 L::pointers(ptr).as_mut().set_next(self.head);
170 L::pointers(ptr).as_mut().set_prev(None);
171
172 if let Some(head) = self.head {
173 L::pointers(head).as_mut().set_prev(Some(ptr));
174 }
175
176 self.head = Some(ptr);
177
178 // if self.tail.is_none() {
179 // self.tail = Some(ptr);
180 // }
181 }
182 }
183
184 // /// Removes the last element from a list and returns it, or None if it is
185 // /// empty.

Callers 5

track_objectMethod · 0.80
promote_survivorsMethod · 0.80
freezeMethod · 0.80
unfreezeMethod · 0.80
appendleftMethod · 0.80

Calls 5

newFunction · 0.85
set_prevMethod · 0.80
SomeClass · 0.50
set_nextMethod · 0.45
as_mutMethod · 0.45

Tested by

no test coverage detected