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

Method remove

crates/common/src/linked_list.rs:235–277  ·  view source on GitHub ↗

Removes the specified node from the list # Safety The caller **must** ensure that `node` is currently contained by `self` or not contained by any other list.

(&mut self, node: NonNull<L::Target>)

Source from the content-addressed store, hash-verified

233 /// The caller **must** ensure that `node` is currently contained by
234 /// `self` or not contained by any other list.
235 pub unsafe fn remove(&mut self, node: NonNull<L::Target>) -> Option<L::Handle> {
236 unsafe {
237 if let Some(prev) = L::pointers(node).as_ref().get_prev() {
238 debug_assert_eq!(
239 L::pointers(prev).as_ref().get_next(),
240 Some(node),
241 "linked list corruption: prev->next != node (prev={prev:p}, node={node:p})"
242 );
243 L::pointers(prev)
244 .as_mut()
245 .set_next(L::pointers(node).as_ref().get_next());
246 } else {
247 if self.head != Some(node) {
248 return None;
249 }
250
251 self.head = L::pointers(node).as_ref().get_next();
252 }
253
254 if let Some(next) = L::pointers(node).as_ref().get_next() {
255 debug_assert_eq!(
256 L::pointers(next).as_ref().get_prev(),
257 Some(node),
258 "linked list corruption: next->prev != node (next={next:p}, node={node:p})"
259 );
260 L::pointers(next)
261 .as_mut()
262 .set_prev(L::pointers(node).as_ref().get_prev());
263 } else {
264 // // This might be the last item in the list
265 // if self.tail != Some(node) {
266 // return None;
267 // }
268
269 // self.tail = L::pointers(node).as_ref().get_prev();
270 }
271
272 L::pointers(node).as_mut().set_next(None);
273 L::pointers(node).as_mut().set_prev(None);
274
275 Some(L::from_raw(node))
276 }
277 }
278
279 // pub fn last(&self) -> Option<&L::Target> {
280 // let tail = self.tail.as_ref()?;

Callers 1

nextMethod · 0.45

Calls 7

get_prevMethod · 0.80
get_nextMethod · 0.80
set_prevMethod · 0.80
SomeClass · 0.50
as_refMethod · 0.45
set_nextMethod · 0.45
as_mutMethod · 0.45

Tested by

no test coverage detected