From 7924cf0aa8306bc8869895cfcf58e6ef83ffc213 Mon Sep 17 00:00:00 2001 From: JackDoan Date: Wed, 6 May 2026 15:46:17 -0500 Subject: [PATCH] use clear() --- overlay/batch/passthrough.go | 4 +--- overlay/batch/tcp_coalesce.go | 12 +++--------- overlay/batch/tx_batch.go | 4 +--- overlay/batch/udp_coalesce.go | 12 +++--------- 4 files changed, 8 insertions(+), 24 deletions(-) diff --git a/overlay/batch/passthrough.go b/overlay/batch/passthrough.go index d971c303..c7676ccd 100644 --- a/overlay/batch/passthrough.go +++ b/overlay/batch/passthrough.go @@ -48,9 +48,7 @@ func (p *Passthrough) Flush() error { firstErr = err } } - for i := range p.slots { - p.slots[i] = nil - } + clear(p.slots) p.slots = p.slots[:0] p.backing = p.backing[:0] return firstErr diff --git a/overlay/batch/tcp_coalesce.go b/overlay/batch/tcp_coalesce.go index c957a138..26d6bb1e 100644 --- a/overlay/batch/tcp_coalesce.go +++ b/overlay/batch/tcp_coalesce.go @@ -266,13 +266,9 @@ func (c *TCPCoalescer) Flush() error { } c.release(s) } - for i := range c.slots { - c.slots[i] = nil - } + clear(c.slots) c.slots = c.slots[:0] - for k := range c.openSlots { - delete(c.openSlots, k) - } + clear(c.openSlots) c.lastSlot = nil c.backing = c.backing[:0] @@ -383,9 +379,7 @@ func (c *TCPCoalescer) take() *coalesceSlot { func (c *TCPCoalescer) release(s *coalesceSlot) { s.passthrough = false s.rawPkt = nil - for i := range s.payIovs { - s.payIovs[i] = nil - } + clear(s.payIovs) s.payIovs = s.payIovs[:0] s.numSeg = 0 s.totalPay = 0 diff --git a/overlay/batch/tx_batch.go b/overlay/batch/tx_batch.go index b7f219a5..0b12b67e 100644 --- a/overlay/batch/tx_batch.go +++ b/overlay/batch/tx_batch.go @@ -55,9 +55,7 @@ func (b *SendBatch) Flush() error { if len(b.bufs) > 0 { err = b.out.WriteBatch(b.bufs, b.dsts, b.ecns) } - for i := range b.bufs { - b.bufs[i] = nil - } + clear(b.bufs) b.bufs = b.bufs[:0] b.dsts = b.dsts[:0] b.ecns = b.ecns[:0] diff --git a/overlay/batch/udp_coalesce.go b/overlay/batch/udp_coalesce.go index 29e79677..25b44613 100644 --- a/overlay/batch/udp_coalesce.go +++ b/overlay/batch/udp_coalesce.go @@ -180,13 +180,9 @@ func (c *UDPCoalescer) Flush() error { } c.release(s) } - for i := range c.slots { - c.slots[i] = nil - } + clear(c.slots) c.slots = c.slots[:0] - for k := range c.openSlots { - delete(c.openSlots, k) - } + clear(c.openSlots) c.backing = c.backing[:0] return first } @@ -270,9 +266,7 @@ func (c *UDPCoalescer) take() *udpSlot { func (c *UDPCoalescer) release(s *udpSlot) { s.passthrough = false s.rawPkt = nil - for i := range s.payIovs { - s.payIovs[i] = nil - } + clear(s.payIovs) s.payIovs = s.payIovs[:0] s.numSeg = 0 s.totalPay = 0