Skip to content

Commit a23ecc6

Browse files
cdelerpgjones
authored andcommitted
Speed up maybe_extract_lines and removed unused variables
using these test results #115 (comment)
1 parent 3247e28 commit a23ecc6

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

h11/_readers.py

-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
from ._abnf import chunk_header, header_field, request_line, status_line
2222
from ._events import *
23-
from ._receivebuffer import line_delimiter_regex
2423
from ._state import *
2524
from ._util import LocalProtocolError, RemoteProtocolError, validate
2625

h11/_receivebuffer.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@
4242
# than the internal bytearray support.)
4343

4444
blank_line_delimiter_regex = re.compile(b"\n\r?\n", re.MULTILINE)
45-
line_delimiter_regex = re.compile(b"\r?\n", re.MULTILINE)
45+
46+
47+
def rstrip_line(line):
48+
return line.rstrip(b"\r")
4649

4750

4851
class ReceiveBuffer(object):
@@ -126,6 +129,6 @@ def maybe_extract_lines(self):
126129
if data is None:
127130
return None
128131

129-
lines = line_delimiter_regex.split(data.rstrip(b"\r\n"))
132+
lines = list(map(rstrip_line, data.rstrip(b"\r\n").split(b"\n")))
130133

131134
return lines

0 commit comments

Comments
 (0)