]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
OK, one more hack: speed up the case of readline() in unbuffered mode.
authorGuido van Rossum <guido@python.org>
Thu, 8 Aug 2002 17:34:19 +0000 (17:34 +0000)
committerGuido van Rossum <guido@python.org>
Thu, 8 Aug 2002 17:34:19 +0000 (17:34 +0000)
This is important IMO because httplib reads the headers this way.

Lib/socket.py

index 833a456b4fd0b310ad1a595771015302be73183d..0daeadcb3483b9a3974f19dd3493a1709b2ae739 100644 (file)
@@ -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