summaryrefslogtreecommitdiffstats
path: root/Lib/socket.py
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2002-08-08 17:34:19 (GMT)
committerGuido van Rossum <guido@python.org>2002-08-08 17:34:19 (GMT)
commit48b7969af8aa537c306eeec8d22235f360c229ed (patch)
tree3b2fe748d2f7c4d4d826c91259be9d9907d78080 /Lib/socket.py
parentfb3deec2fc81a4bf7e16ddbaa8271005524ab1b0 (diff)
downloadcpython-48b7969af8aa537c306eeec8d22235f360c229ed.zip
cpython-48b7969af8aa537c306eeec8d22235f360c229ed.tar.gz
cpython-48b7969af8aa537c306eeec8d22235f360c229ed.tar.bz2
OK, one more hack: speed up the case of readline() in unbuffered mode.
This is important IMO because httplib reads the headers this way.
Diffstat (limited to 'Lib/socket.py')
-rw-r--r--Lib/socket.py11
1 files changed, 11 insertions, 0 deletions
diff --git a/Lib/socket.py b/Lib/socket.py
index 833a456..0daeadc 100644
--- a/Lib/socket.py
+++ b/Lib/socket.py
@@ -307,6 +307,17 @@ class _fileobject(object):
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