Skip to content

Commit 0ff106f

Browse files
committed
Make TCPTransport.writelines flatten the bufs list (like in asyncio)
1 parent 358d1cb commit 0ff106f

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

uvloop/handles/stream.pyx

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -279,19 +279,16 @@ cdef class UVStream(UVBaseTransport):
279279
self._maybe_pause_protocol()
280280

281281
def writelines(self, bufs):
282-
self._ensure_alive()
283-
284-
if self._eof:
285-
raise RuntimeError('Cannot call writelines() after write_eof()')
286-
if self._conn_lost:
287-
self._conn_lost += 1
288-
return
289-
290-
for buf in bufs:
291-
if buf:
292-
self._write(buf)
293-
294-
self._maybe_pause_protocol()
282+
# Instead of flattening the buffers into one bytes object,
283+
# we could simply call `self._write` multiple times. That
284+
# would be more efficient, as we wouldn't be copying data
285+
# (and thus allocating more memory).
286+
# On the other hand, uvloop would behave differently from
287+
# asyncio: where asyncio does one send op, uvloop would do
288+
# many send ops. If the program uses TCP_NODELAY sock opt,
289+
# this different behavior may result in uvloop being slower
290+
# than asyncio.
291+
self.write(b''.join(bufs))
295292

296293
def write_eof(self):
297294
self._ensure_alive()

0 commit comments

Comments
 (0)