From ba548cbc8e45b931aff88128705deb8116ab35ea Mon Sep 17 00:00:00 2001 From: Joe Date: Tue, 9 Jan 2024 20:20:20 +0100 Subject: delete fixed --- c_lhosts.go | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'c_lhosts.go') diff --git a/c_lhosts.go b/c_lhosts.go index 74726d8..4041279 100644 --- a/c_lhosts.go +++ b/c_lhosts.go @@ -112,6 +112,15 @@ func (lhost *HostList) del(host *HostNode) { } return } + if lhost.last == host { + ptr := lhost.head + for ptr.next != nil { + ptr = ptr.next + } + lhost.last = ptr + lhost.last.next = nil + return + } ptr := lhost.head for ptr.next != nil && ptr.next != host { ptr = ptr.next @@ -122,13 +131,6 @@ func (lhost *HostList) del(host *HostNode) { for ptr := ptr.next; ptr != nil; ptr = ptr.next { ptr.ID -= 1 } - if lhost.last == host { - ptr := lhost.head - for ptr.next != nil { - ptr = ptr.next - } - lhost.last = ptr - } } // return the list node with the according id -- cgit v1.2.3