gh-141968: use bytearray.take_bytes in encodings.idna (#141975)

This commit is contained in:
Cody Maloney 2025-11-26 07:46:25 -08:00 committed by GitHub
parent 9dbf77beb6
commit 9ac14288d7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 5 additions and 2 deletions

View file

@ -226,7 +226,8 @@ def encode(self, input, errors='strict'):
offset + exc.end,
exc.reason,
)
return bytes(result+trailing_dot), len(input)
result += trailing_dot
return result.take_bytes(), len(input)
def decode(self, input, errors='strict'):
@ -311,7 +312,7 @@ def _buffer_encode(self, input, errors, final):
result += trailing_dot
size += len(trailing_dot)
return (bytes(result), size)
return (result.take_bytes(), size)
class IncrementalDecoder(codecs.BufferedIncrementalDecoder):
def _buffer_decode(self, input, errors, final):

View file

@ -0,0 +1,2 @@
Remove data copy from :mod:`encodings.idna` :meth:`~codecs.Codec.encode` and
:meth:`~codecs.IncrementalEncoder.encode` by using :func:`bytearray.take_bytes`.