Skip to content

Commit

Permalink
wire: reduce allocations when parsing transport parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
marten-seemann committed May 5, 2024
1 parent 1514095 commit 11dd7ca
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions internal/wire/transport_parameters.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"fmt"
"io"
"net/netip"
"sort"
"slices"
"time"

"github.com/quic-go/quic-go/internal/protocol"
Expand Down Expand Up @@ -98,7 +98,7 @@ func (p *TransportParameters) Unmarshal(data []byte, sentBy protocol.Perspective

func (p *TransportParameters) unmarshal(b []byte, sentBy protocol.Perspective, fromSessionTicket bool) error {
// needed to check that every parameter is only sent at most once
var parameterIDs []transportParameterID
parameterIDs := make([]transportParameterID, 0, 32)

var (
readOriginalDestinationConnectionID bool
Expand Down Expand Up @@ -220,7 +220,12 @@ func (p *TransportParameters) unmarshal(b []byte, sentBy protocol.Perspective, f
}

// check that every transport parameter was sent at most once
sort.Slice(parameterIDs, func(i, j int) bool { return parameterIDs[i] < parameterIDs[j] })
slices.SortFunc(parameterIDs, func(a, b transportParameterID) int {
if a < b {
return -1
}
return 1
})
for i := 0; i < len(parameterIDs)-1; i++ {
if parameterIDs[i] == parameterIDs[i+1] {
return fmt.Errorf("received duplicate transport parameter %#x", parameterIDs[i])
Expand Down

0 comments on commit 11dd7ca

Please sign in to comment.