From: Guido van Rossum Date: Thu, 8 Aug 2002 17:34:19 +0000 (+0000) Subject: OK, one more hack: speed up the case of readline() in unbuffered mode. X-Git-Tag: v2.3c1~4613 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=48b7969af8aa537c306eeec8d22235f360c229ed;p=thirdparty%2FPython%2Fcpython.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. --- diff --git a/Lib/socket.py b/Lib/socket.py index 833a456b4fd0..0daeadcb3483 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