feat: speed up bytearray creation in unmarshaller (#382)

This commit is contained in:
J. Nick Koston 2025-02-01 23:37:13 -06:00 committed by GitHub
parent f6f2497eb2
commit 89026e3b59
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -243,7 +243,7 @@ class Unmarshaller:
negotiate_unix_fd: bool = True,
) -> None:
self._unix_fds: list[int] = []
self._buf = bytearray() # Actual buffer
self._buf = bytearray.__new__(bytearray) # Actual buffer
self._stream = stream
self._sock = sock
self._message: Optional[Message] = None
@ -280,7 +280,7 @@ class Unmarshaller:
self._unix_fds = []
to_clear = HEADER_SIGNATURE_SIZE + self._msg_len
if len(self._buf) == to_clear:
self._buf = bytearray()
self._buf = bytearray.__new__(bytearray)
else:
del self._buf[:to_clear]
self._msg_len = 0 # used to check if we have ready the header