Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use bytearray instead of a list of bytes in websocket reader #3039

Merged
merged 2 commits into from
May 31, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES/3039.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Use ``bytearray`` instead of a list of ``bytes`` in websocket reader. It improves websocket message reading a little.
13 changes: 7 additions & 6 deletions aiohttp/http_websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ def __init__(self, queue, compress=True):
self.queue = queue

self._exc = None
self._partial = []
self._partial = bytearray()
self._state = WSParserState.READ_HEADER

self._opcode = None
Expand Down Expand Up @@ -319,7 +319,7 @@ def _feed_data(self, data):
# got partial frame payload
if opcode != WSMsgType.CONTINUATION:
self._opcode = opcode
self._partial.append(payload)
self._partial.extend(payload)
else:
# previous frame was non finished
# we should get continuation opcode
Expand All @@ -334,15 +334,16 @@ def _feed_data(self, data):
opcode = self._opcode
self._opcode = None

self._partial.append(payload)

payload_merged = b''.join(self._partial)
self._partial.extend(payload)

# Decompress process must to be done after all packets
# received.
if compressed:
self._partial.extend(_WS_DEFLATE_TRAILING)
payload_merged = self._decompressobj.decompress(
payload_merged + _WS_DEFLATE_TRAILING)
self._partial)
else:
payload_merged = bytes(self._partial)

self._partial.clear()

Expand Down