Skip to content

Commit

Permalink
Improve bytearray cast comment
Browse files Browse the repository at this point in the history
  • Loading branch information
zanieb authored and pgjones committed Aug 24, 2022
1 parent 5a20880 commit 98e3587
Showing 1 changed file with 1 addition and 3 deletions.
4 changes: 1 addition & 3 deletions h11/_readers.py
Expand Up @@ -37,9 +37,6 @@
__all__ = ["READERS"]

header_field_re = re.compile(header_field.encode("ascii"))

# Remember that this has to run in O(n) time -- so e.g. the bytearray cast is
# critical.
obs_fold_re = re.compile(rb"[ \t]+")


Expand All @@ -52,6 +49,7 @@ def _obsolete_line_fold(lines: Iterable[bytes]) -> Iterable[bytes]:
if last is None:
raise LocalProtocolError("continuation line at start of headers")
if not isinstance(last, bytearray):
# Cast to a mutable type, avoiding copy on append to ensure O(n) time
last = bytearray(last)
last += b" "
last += line[match.end() :]
Expand Down

0 comments on commit 98e3587

Please sign in to comment.