Skip to content

Commit b535981

Browse files
[PR #9554/ec19bfa7 backport][3.11] Optimize WebSocketReader for 2 byte length case (#9555)
Co-authored-by: J. Nick Koston <[email protected]>
1 parent ecb6490 commit b535981

File tree

4 files changed

+5
-5
lines changed

4 files changed

+5
-5
lines changed

CHANGES/9554.feature.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
9543.feature.rst

aiohttp/_websocket/helpers.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
from ..helpers import NO_EXTENSIONS
99
from .models import WSHandshakeError
1010

11-
UNPACK_LEN2 = Struct("!H").unpack_from
1211
UNPACK_LEN3 = Struct("!Q").unpack_from
1312
UNPACK_CLOSE_CODE = Struct("!H").unpack
1413
PACK_LEN1 = Struct("!BB").pack

aiohttp/_websocket/reader_c.pxd

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ cdef unsigned int OP_CODE_CLOSE
1515
cdef unsigned int OP_CODE_PING
1616
cdef unsigned int OP_CODE_PONG
1717

18-
cdef object UNPACK_LEN2
1918
cdef object UNPACK_LEN3
2019
cdef object UNPACK_CLOSE_CODE
2120
cdef object TUPLE_NEW

aiohttp/_websocket/reader_py.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from ..compression_utils import ZLibDecompressor
66
from ..helpers import set_exception
77
from ..streams import DataQueue
8-
from .helpers import UNPACK_CLOSE_CODE, UNPACK_LEN2, UNPACK_LEN3, websocket_mask
8+
from .helpers import UNPACK_CLOSE_CODE, UNPACK_LEN3, websocket_mask
99
from .models import (
1010
WS_DEFLATE_TRAILING,
1111
WebSocketError,
@@ -310,9 +310,10 @@ def parse_frame(
310310
if length_flag == 126:
311311
if buf_length - start_pos < 2:
312312
break
313-
data = buf[start_pos : start_pos + 2]
313+
first_byte = buf[start_pos]
314+
second_byte = buf[start_pos + 1]
314315
start_pos += 2
315-
self._payload_length = UNPACK_LEN2(data)[0]
316+
self._payload_length = first_byte << 8 | second_byte
316317
elif length_flag > 126:
317318
if buf_length - start_pos < 8:
318319
break

0 commit comments

Comments
 (0)