mercurial/httpclient/__init__.py
changeset 19038 36733ab7fa05
parent 17537 31f32a96e1e3
child 19182 fae47ecaa952
--- a/mercurial/httpclient/__init__.py	Fri Feb 01 14:41:35 2013 -0800
+++ b/mercurial/httpclient/__init__.py	Fri Feb 01 15:00:23 2013 -0800
@@ -125,24 +125,16 @@
         This may block until either a line ending is found or the
         response is complete.
         """
-        # TODO: move this into the reader interface where it can be
-        # smarter (and probably avoid copies)
-        bytes = []
-        while not bytes:
-            try:
-                bytes = [self._reader.read(1)]
-            except _readers.ReadNotReady:
-                self._select()
-        while bytes[-1] != '\n' and not self.complete():
+        blocks = []
+        while True:
+            self._reader.readto('\n', blocks)
+
+            if blocks and blocks[-1][-1] == '\n' or self.complete():
+                break
+
             self._select()
-            bytes.append(self._reader.read(1))
-        if bytes[-1] != '\n':
-            next = self._reader.read(1)
-            while next and next != '\n':
-                bytes.append(next)
-                next = self._reader.read(1)
-            bytes.append(next)
-        return ''.join(bytes)
+
+        return ''.join(blocks)
 
     def read(self, length=None):
         # if length is None, unbounded read