From 643fdd0bce632229e99e42c4ff0389fecaf28d74 Mon Sep 17 00:00:00 2001 From: wwqgtxx Date: Mon, 16 Jan 2023 09:54:52 +0800 Subject: [PATCH] chore: tuic decrease unneeded copy --- transport/tuic/protocol.go | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/transport/tuic/protocol.go b/transport/tuic/protocol.go index ab696e79..a54c8e54 100644 --- a/transport/tuic/protocol.go +++ b/transport/tuic/protocol.go @@ -454,12 +454,10 @@ func NewAddress(metadata *C.Metadata) Address { switch metadata.AddrType() { case socks5.AtypIPv4: addrType = AtypIPv4 - addr = make([]byte, net.IPv4len) - copy(addr[:], metadata.DstIP.AsSlice()) + addr = metadata.DstIP.AsSlice() case socks5.AtypIPv6: addrType = AtypIPv6 - addr = make([]byte, net.IPv6len) - copy(addr[:], metadata.DstIP.AsSlice()) + addr = metadata.DstIP.AsSlice() case socks5.AtypDomainName: addrType = AtypDomainName addr = make([]byte, len(metadata.Host)+1) @@ -478,18 +476,14 @@ func NewAddress(metadata *C.Metadata) Address { func NewAddressAddrPort(addrPort netip.AddrPort) Address { var addrType byte - var addr []byte if addrPort.Addr().Is4() { addrType = AtypIPv4 - addr = make([]byte, net.IPv4len) } else { addrType = AtypIPv6 - addr = make([]byte, net.IPv6len) } - copy(addr[:], addrPort.Addr().AsSlice()) return Address{ TYPE: addrType, - ADDR: addr, + ADDR: addrPort.Addr().AsSlice(), PORT: addrPort.Port(), } }