Commit 5e74742b authored by Jason Madden's avatar Jason Madden Committed by GitHub

Merge pull request #1241 from gevent/issue1233

Use bytearray += instead of bytearray.extend
parents 23cc4322 fcbdd238
...@@ -16,6 +16,9 @@ ...@@ -16,6 +16,9 @@
way :mod:`gevent.pywsgi` generates HTTP chunks. This is intended to way :mod:`gevent.pywsgi` generates HTTP chunks. This is intended to
reduce network overhead, especially for smaller chunk sizes. reduce network overhead, especially for smaller chunk sizes.
- Additional slight performance improvements in :mod:`gevent.pywsgi`.
See :pr:`1241`.
1.3.3 (2018-06-08) 1.3.3 (2018-06-08)
================== ==================
......
...@@ -733,9 +733,9 @@ class WSGIHandler(object): ...@@ -733,9 +733,9 @@ class WSGIHandler(object):
towrite = _bytearray(header_str) towrite = _bytearray(header_str)
# data # data
towrite.extend(data) towrite += data
# trailer # trailer
towrite.extend(b'\r\n') towrite += b'\r\n'
self._sendall(towrite) self._sendall(towrite)
else: else:
self._sendall(data) self._sendall(data)
...@@ -756,21 +756,20 @@ class WSGIHandler(object): ...@@ -756,21 +756,20 @@ class WSGIHandler(object):
self._write_with_headers(data) self._write_with_headers(data)
def _write_with_headers(self, data): def _write_with_headers(self, data):
towrite = bytearray()
self.headers_sent = True self.headers_sent = True
self.finalize_headers() self.finalize_headers()
# self.response_headers and self.status are already in latin-1, as encoded by self.start_response # self.response_headers and self.status are already in latin-1, as encoded by self.start_response
towrite.extend(b'HTTP/1.1 ') towrite = bytearray(b'HTTP/1.1 ')
towrite.extend(self.status) towrite += self.status
towrite.extend(b'\r\n') towrite += b'\r\n'
for header, value in self.response_headers: for header, value in self.response_headers:
towrite.extend(header) towrite += header
towrite.extend(b': ') towrite += b': '
towrite.extend(value) towrite += value
towrite.extend(b"\r\n") towrite += b"\r\n"
towrite.extend(b'\r\n') towrite += b'\r\n'
self._sendall(towrite) self._sendall(towrite)
# No need to copy the data into towrite; we may make an extra syscall # No need to copy the data into towrite; we may make an extra syscall
# but the copy time could be substantial too, and it reduces the chances # but the copy time could be substantial too, and it reduces the chances
...@@ -914,8 +913,8 @@ class WSGIHandler(object): ...@@ -914,8 +913,8 @@ class WSGIHandler(object):
# Trigger the flush of the headers. # Trigger the flush of the headers.
self.write(b'') self.write(b'')
if self.response_use_chunked: if self.response_use_chunked:
self.socket.sendall(b'0\r\n\r\n') self._sendall(b'0\r\n\r\n')
self.response_length += 5
def run_application(self): def run_application(self):
assert self.result is None assert self.result is None
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment