From 70b49fba2d2b39cf2111dd25ebb419985fdb6fc6 Mon Sep 17 00:00:00 2001 From: Marco Munizaga Date: Tue, 11 Apr 2023 11:09:20 -0700 Subject: [PATCH] Nits --- p2p/host/basic/basic_host.go | 2 ++ p2p/host/basic/basic_host_test.go | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/p2p/host/basic/basic_host.go b/p2p/host/basic/basic_host.go index aa1dbaf058..27318f6b7d 100644 --- a/p2p/host/basic/basic_host.go +++ b/p2p/host/basic/basic_host.go @@ -1013,6 +1013,8 @@ var wtComponent = ma.StringCast("/webtransport") func inferWebtransportAddrsFromQuic(in []ma.Multiaddr) []ma.Multiaddr { // We need to check if we are listening on the same ip+port for QUIC and WebTransport. // If not, there's nothing to do since we can't infer anything. + + // Count the number of QUIC addrs, this will let us allocate just once at the beginning. quicAddrCount := 0 for _, addr := range in { if _, lastComponent := ma.SplitLast(addr); lastComponent.Protocol().Code == ma.P_QUIC_V1 { diff --git a/p2p/host/basic/basic_host_test.go b/p2p/host/basic/basic_host_test.go index f607a9d698..5c1babd9d5 100644 --- a/p2p/host/basic/basic_host_test.go +++ b/p2p/host/basic/basic_host_test.go @@ -884,7 +884,7 @@ func TestInferWebtransportAddrsFromQuic(t *testing.T) { min = append(min, ma.StringCast(addr)) } outMa := inferWebtransportAddrsFromQuic(min) - outStr := make([]string, 0, len(tc.out)) + outStr := make([]string, 0, len(outMa)) for _, addr := range outMa { outStr = append(outStr, addr.String()) }