OK, one more hack: speed up the case of readline() in unbuffered mode.

This is important IMO because httplib reads the headers this way.
This commit is contained in:
Guido van Rossum 2002-08-08 17:34:19 +00:00
parent fb3deec2fc
commit 48b7969af8
1 changed files with 11 additions and 0 deletions

View File

@ -307,6 +307,17 @@ def readline(self, size=-1):
data = self._rbuf
if size < 0:
# Read until \n or EOF, whichever comes first
if self._rbufsize <= 1:
# Speed up unbuffered case
assert data == ""
buffers = []
recv = self._sock.recv
while data != "\n":
data = recv(1)
if not data:
break
buffers.append(data)
return "".join(buffers)
nl = data.find('\n')
if nl >= 0:
nl += 1