Skip to content

Commit

Permalink
Extract constant, add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
bdarnell committed May 26, 2012
1 parent 227becd commit 3dcf497
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions tornado/iostream.py
Expand Up @@ -189,12 +189,16 @@ def write(self, data, callback=None):
"""
assert isinstance(data, bytes_type)
self._check_closed()
# We use bool(_write_buffer) as a proxy for write_buffer_size>0,
# so never put empty strings in the buffer.
if data:
# We use bool(_write_buffer) as a proxy for write_buffer_size>0,
# so never put empty strings in the buffer.
if len(data) > 128*1024:
for i in range(0, len(data), 128*1024):
self._write_buffer.append(data[i:i+128*1024])
# Break up large contiguous strings before inserting them in the
# write buffer, so we don't have to recopy the entire thing
# as we slice off pieces to send to the socket.
WRITE_BUFFER_CHUNK_SIZE = 128 * 1024
if len(data) > WRITE_BUFFER_CHUNK_SIZE:
for i in range(0, len(data), WRITE_BUFFER_CHUNK_SIZE):
self._write_buffer.append(data[i:i+WRITE_BUFFER_CHUNK_SIZE])
else:
self._write_buffer.append(data)
self._write_callback = stack_context.wrap(callback)
Expand Down

0 comments on commit 3dcf497

Please sign in to comment.