http3: avoid allocation when parsing the datagram's quarter stream ID (#4478)

This commit is contained in:
Marten Seemann
2024-05-03 14:13:38 +02:00
committed by GitHub
parent 11111228cf
commit 3122ca009b

View File

@@ -1,7 +1,6 @@
package http3 package http3
import ( import (
"bytes"
"context" "context"
"fmt" "fmt"
"log/slog" "log/slog"
@@ -252,9 +251,7 @@ func (c *connection) receiveDatagrams() error {
if err != nil { if err != nil {
return err return err
} }
// TODO: this is quite wasteful in terms of allocations quarterStreamID, n, err := quicvarint.Parse(b)
r := bytes.NewReader(b)
quarterStreamID, err := quicvarint.Read(r)
if err != nil { if err != nil {
c.Connection.CloseWithError(quic.ApplicationErrorCode(ErrCodeDatagramError), "") c.Connection.CloseWithError(quic.ApplicationErrorCode(ErrCodeDatagramError), "")
return fmt.Errorf("could not read quarter stream id: %w", err) return fmt.Errorf("could not read quarter stream id: %w", err)
@@ -271,7 +268,7 @@ func (c *connection) receiveDatagrams() error {
return nil return nil
} }
c.streamMx.Unlock() c.streamMx.Unlock()
dg.enqueue(b[len(b)-r.Len():]) dg.enqueue(b[n:])
} }
} }