From 0827a6f1c5715c78829c8c03870d87ea4c4b7188 Mon Sep 17 00:00:00 2001 From: Jay Wren Date: Thu, 23 Oct 2025 13:27:37 -0400 Subject: [PATCH] claude suggests this bound checking optimization it is about 4.4% better on the bench-cpu-long cpu usage test --- outside.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/outside.go b/outside.go index 5ff87bd..c907198 100644 --- a/outside.go +++ b/outside.go @@ -333,12 +333,13 @@ func parseV6(data []byte, incoming bool, fp *firewall.Packet) error { } fp.Protocol = uint8(proto) + ports := data[offset : offset+4] if incoming { - fp.RemotePort = binary.BigEndian.Uint16(data[offset : offset+2]) - fp.LocalPort = binary.BigEndian.Uint16(data[offset+2 : offset+4]) + fp.RemotePort = binary.BigEndian.Uint16(ports[0:2]) + fp.LocalPort = binary.BigEndian.Uint16(ports[2:4]) } else { - fp.LocalPort = binary.BigEndian.Uint16(data[offset : offset+2]) - fp.RemotePort = binary.BigEndian.Uint16(data[offset+2 : offset+4]) + fp.LocalPort = binary.BigEndian.Uint16(ports[0:2]) + fp.RemotePort = binary.BigEndian.Uint16(ports[2:4]) } fp.Fragment = false