forked from quic-go/quic-go
wire: optimize parsing logic for STREAM, DATAGRAM and ACK frames (#5227)
ParseOtherFrames-16 148ns ± 4% 150ns ± 3% ~ (p=0.223 n=8+8) ParseAckFrame-16 302ns ± 2% 298ns ± 3% ~ (p=0.246 n=8+8) ParseStreamFrame-16 262ns ± 3% 213ns ± 2% -18.61% (p=0.000 n=8+8) ParseDatagramFrame-16 561ns ± 5% 547ns ± 4% ~ (p=0.105 n=8+8)
This commit is contained in:
@@ -13,7 +13,7 @@ import (
|
||||
|
||||
func TestParseMaxStreamsFrameBidirectional(t *testing.T) {
|
||||
data := encodeVarInt(0xdecaf)
|
||||
f, l, err := parseMaxStreamsFrame(data, bidiMaxStreamsFrameType, protocol.Version1)
|
||||
f, l, err := parseMaxStreamsFrame(data, FrameTypeBidiMaxStreams, protocol.Version1)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, protocol.StreamTypeBidi, f.Type)
|
||||
require.EqualValues(t, 0xdecaf, f.MaxStreamNum)
|
||||
@@ -22,7 +22,7 @@ func TestParseMaxStreamsFrameBidirectional(t *testing.T) {
|
||||
|
||||
func TestParseMaxStreamsFrameUnidirectional(t *testing.T) {
|
||||
data := encodeVarInt(0xdecaf)
|
||||
f, l, err := parseMaxStreamsFrame(data, uniMaxStreamsFrameType, protocol.Version1)
|
||||
f, l, err := parseMaxStreamsFrame(data, FrameTypeUniMaxStreams, protocol.Version1)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, protocol.StreamTypeUni, f.Type)
|
||||
require.EqualValues(t, 0xdecaf, f.MaxStreamNum)
|
||||
@@ -59,7 +59,7 @@ func TestParseMaxStreamsMaxValue(t *testing.T) {
|
||||
typ, l, err := quicvarint.Parse(b)
|
||||
require.NoError(t, err)
|
||||
b = b[l:]
|
||||
frame, _, err := parseMaxStreamsFrame(b, typ, protocol.Version1)
|
||||
frame, _, err := parseMaxStreamsFrame(b, FrameType(typ), protocol.Version1)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, f, frame)
|
||||
})
|
||||
@@ -84,7 +84,7 @@ func TestParseMaxStreamsErrorsOnTooLargeStreamCount(t *testing.T) {
|
||||
typ, l, err := quicvarint.Parse(b)
|
||||
require.NoError(t, err)
|
||||
b = b[l:]
|
||||
_, _, err = parseMaxStreamsFrame(b, typ, protocol.Version1)
|
||||
_, _, err = parseMaxStreamsFrame(b, FrameType(typ), protocol.Version1)
|
||||
require.EqualError(t, err, fmt.Sprintf("%d exceeds the maximum stream count", protocol.MaxStreamCount+1))
|
||||
})
|
||||
}
|
||||
@@ -97,7 +97,7 @@ func TestWriteMaxStreamsBidirectional(t *testing.T) {
|
||||
}
|
||||
b, err := f.Append(nil, protocol.Version1)
|
||||
require.NoError(t, err)
|
||||
expected := []byte{bidiMaxStreamsFrameType}
|
||||
expected := []byte{byte(FrameTypeBidiMaxStreams)}
|
||||
expected = append(expected, encodeVarInt(0xdeadbeef)...)
|
||||
require.Equal(t, expected, b)
|
||||
require.Len(t, b, int(f.Length(protocol.Version1)))
|
||||
@@ -110,7 +110,7 @@ func TestWriteMaxStreamsUnidirectional(t *testing.T) {
|
||||
}
|
||||
b, err := f.Append(nil, protocol.Version1)
|
||||
require.NoError(t, err)
|
||||
expected := []byte{uniMaxStreamsFrameType}
|
||||
expected := []byte{byte(FrameTypeUniMaxStreams)}
|
||||
expected = append(expected, encodeVarInt(0xdecafbad)...)
|
||||
require.Equal(t, expected, b)
|
||||
require.Len(t, b, int(f.Length(protocol.Version1)))
|
||||
|
||||
Reference in New Issue
Block a user