From 235184774e41b30f272ac58ded1e0dafa7e93eac Mon Sep 17 00:00:00 2001 From: Julian Orth Date: Wed, 21 May 2025 19:44:01 +0200 Subject: [PATCH] linked-list: properly detach other root node in append_all --- src/utils/linkedlist.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/utils/linkedlist.rs b/src/utils/linkedlist.rs index 0fde4b90..251c43a3 100644 --- a/src/utils/linkedlist.rs +++ b/src/utils/linkedlist.rs @@ -35,19 +35,21 @@ impl LinkedList { } pub fn append_all(&self, other: &LinkedList) { - if other.is_empty() { + if other.is_empty() || self.root.data == other.root.data { return; } unsafe { - let o_root = other.root.data.as_ref(); - let o_first = o_root.next.get(); - let o_last = o_root.prev.get(); + let o_root = other.root.data; + let o_first = o_root.as_ref().next.get(); + let o_last = o_root.as_ref().prev.get(); let s_first = self.root.data; let s_last = s_first.as_ref().prev.get(); o_first.as_ref().prev.set(s_last); s_last.as_ref().next.set(o_first); o_last.as_ref().next.set(s_first); s_first.as_ref().prev.set(o_last); + o_root.as_ref().next.set(o_root); + o_root.as_ref().prev.set(o_root); } }