mirror of https://github.com/python/cpython.git
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:
parent
fb3deec2fc
commit
48b7969af8
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue