sshpeer: don't read(0)
authorGregory Szorc <gregory.szorc@gmail.com>
Fri, 02 Mar 2018 22:59:12 -0500
changeset 36657 70415568ea65
parent 36656 418f9ea20c35
child 36658 c98d1c6763a6
sshpeer: don't read(0) read(0) is essentially a no-op. Let's avoid the function call, overhead, and extra test output by not performing it. Differential Revision: https://phab.mercurial-scm.org/D2581
mercurial/sshpeer.py
tests/test-ssh-proto-unbundle.t
--- a/mercurial/sshpeer.py	Sat Mar 03 05:51:34 2018 -0500
+++ b/mercurial/sshpeer.py	Fri Mar 02 22:59:12 2018 -0500
@@ -523,7 +523,11 @@
             self._abort(error.ResponseError(_("unexpected response:"), l))
 
     def _readframed(self):
-        return self._pipei.read(self._getamount())
+        size = self._getamount()
+        if not size:
+            return b''
+
+        return self._pipei.read(size)
 
     def _writeframed(self, data, flush=False):
         self._pipeo.write("%d\n" % len(data))
--- a/tests/test-ssh-proto-unbundle.t	Sat Mar 03 05:51:34 2018 -0500
+++ b/tests/test-ssh-proto-unbundle.t	Fri Mar 02 22:59:12 2018 -0500
@@ -88,7 +88,6 @@
   i> flush() -> None
   o> readline() -> 2:
   o>     0\n
-  o> read(0) -> 0: 
   o> readline() -> 2:
   o>     1\n
   o> read(1) -> 1: 0
@@ -139,7 +138,6 @@
   i> flush() -> None
   o> readline() -> 2:
   o>     0\n
-  o> read(0) -> 0: 
   o> readline() -> 2:
   o>     1\n
   o> read(1) -> 1: 0
@@ -257,7 +255,6 @@
   i> flush() -> None
   o> readline() -> 2:
   o>     0\n
-  o> read(0) -> 0: 
   o> readline() -> 2:
   o>     1\n
   o> read(1) -> 1: 0
@@ -314,7 +311,6 @@
   i> flush() -> None
   o> readline() -> 2:
   o>     0\n
-  o> read(0) -> 0: 
   o> readline() -> 2:
   o>     1\n
   o> read(1) -> 1: 0
@@ -385,7 +381,6 @@
   i> flush() -> None
   o> readline() -> 2:
   o>     0\n
-  o> read(0) -> 0: 
   o> readline() -> 2:
   o>     1\n
   o> read(1) -> 1: 0
@@ -443,7 +438,6 @@
   i> flush() -> None
   o> readline() -> 2:
   o>     0\n
-  o> read(0) -> 0: 
   o> readline() -> 2:
   o>     1\n
   o> read(1) -> 1: 0
@@ -515,7 +509,6 @@
   i> flush() -> None
   o> readline() -> 2:
   o>     0\n
-  o> read(0) -> 0: 
   o> readline() -> 2:
   o>     1\n
   o> read(1) -> 1: 0
@@ -572,7 +565,6 @@
   i> flush() -> None
   o> readline() -> 2:
   o>     0\n
-  o> read(0) -> 0: 
   o> readline() -> 2:
   o>     1\n
   o> read(1) -> 1: 0
@@ -643,7 +635,6 @@
   i> flush() -> None
   o> readline() -> 2:
   o>     0\n
-  o> read(0) -> 0: 
   o> readline() -> 2:
   o>     1\n
   o> read(1) -> 1: 0
@@ -701,7 +692,6 @@
   i> flush() -> None
   o> readline() -> 2:
   o>     0\n
-  o> read(0) -> 0: 
   o> readline() -> 2:
   o>     1\n
   o> read(1) -> 1: 0
@@ -773,7 +763,6 @@
   i> flush() -> None
   o> readline() -> 2:
   o>     0\n
-  o> read(0) -> 0: 
   o> readline() -> 2:
   o>     1\n
   o> read(1) -> 1: 0
@@ -833,7 +822,6 @@
   i> flush() -> None
   o> readline() -> 2:
   o>     0\n
-  o> read(0) -> 0: 
   o> readline() -> 2:
   o>     1\n
   o> read(1) -> 1: 0
@@ -907,7 +895,6 @@
   i> flush() -> None
   o> readline() -> 2:
   o>     0\n
-  o> read(0) -> 0: 
   o> readline() -> 2:
   o>     1\n
   o> read(1) -> 1: 0
@@ -964,7 +951,6 @@
   i> flush() -> None
   o> readline() -> 2:
   o>     0\n
-  o> read(0) -> 0: 
   o> readline() -> 2:
   o>     1\n
   o> read(1) -> 1: 0
@@ -1035,7 +1021,6 @@
   i> flush() -> None
   o> readline() -> 2:
   o>     0\n
-  o> read(0) -> 0: 
   o> readline() -> 2:
   o>     1\n
   o> read(1) -> 1: 0
@@ -1095,7 +1080,6 @@
   i> flush() -> None
   o> readline() -> 2:
   o>     0\n
-  o> read(0) -> 0: 
   o> readline() -> 2:
   o>     1\n
   o> read(1) -> 1: 0
@@ -1169,7 +1153,6 @@
   i> flush() -> None
   o> readline() -> 2:
   o>     0\n
-  o> read(0) -> 0: 
   o> readline() -> 2:
   o>     1\n
   o> read(1) -> 1: 0
@@ -1229,7 +1212,6 @@
   i> flush() -> None
   o> readline() -> 2:
   o>     0\n
-  o> read(0) -> 0: 
   o> readline() -> 2:
   o>     1\n
   o> read(1) -> 1: 0
@@ -1309,7 +1291,6 @@
   i> flush() -> None
   o> readline() -> 2:
   o>     0\n
-  o> read(0) -> 0: 
   o> readline() -> 2:
   o>     1\n
   o> read(1) -> 1: 0
@@ -1367,7 +1348,6 @@
   i> flush() -> None
   o> readline() -> 2:
   o>     0\n
-  o> read(0) -> 0: 
   o> readline() -> 2:
   o>     1\n
   o> read(1) -> 1: 0
@@ -1440,7 +1420,6 @@
   i> flush() -> None
   o> readline() -> 2:
   o>     0\n
-  o> read(0) -> 0: 
   o> readline() -> 2:
   o>     1\n
   o> read(1) -> 1: 0
@@ -1498,7 +1477,6 @@
   i> flush() -> None
   o> readline() -> 2:
   o>     0\n
-  o> read(0) -> 0: 
   o> readline() -> 2:
   o>     1\n
   o> read(1) -> 1: 0
@@ -1573,7 +1551,6 @@
   i> flush() -> None
   o> readline() -> 2:
   o>     0\n
-  o> read(0) -> 0: 
   o> readline() -> 2:
   o>     1\n
   o> read(1) -> 1: 0
@@ -1633,7 +1610,6 @@
   i> flush() -> None
   o> readline() -> 2:
   o>     0\n
-  o> read(0) -> 0: 
   o> readline() -> 2:
   o>     1\n
   o> read(1) -> 1: 0
@@ -1716,7 +1692,6 @@
   i> flush() -> None
   o> readline() -> 2:
   o>     0\n
-  o> read(0) -> 0: 
   o> readline() -> 2:
   o>     1\n
   o> read(1) -> 1: 0
@@ -1780,7 +1755,6 @@
   i> flush() -> None
   o> readline() -> 2:
   o>     0\n
-  o> read(0) -> 0: 
   o> readline() -> 2:
   o>     1\n
   o> read(1) -> 1: 0
@@ -1858,7 +1832,6 @@
   i> flush() -> None
   o> readline() -> 2:
   o>     0\n
-  o> read(0) -> 0: 
   o> readline() -> 2:
   o>     1\n
   o> read(1) -> 1: 1
@@ -1911,7 +1884,6 @@
   i> flush() -> None
   o> readline() -> 2:
   o>     0\n
-  o> read(0) -> 0: 
   o> readline() -> 2:
   o>     1\n
   o> read(1) -> 1: 1
@@ -1990,7 +1962,6 @@
   i> flush() -> None
   o> readline() -> 2:
   o>     0\n
-  o> read(0) -> 0: 
   o> readline() -> 2:
   o>     1\n
   o> read(1) -> 1: 1
@@ -2047,7 +2018,6 @@
   i> flush() -> None
   o> readline() -> 2:
   o>     0\n
-  o> read(0) -> 0: 
   o> readline() -> 2:
   o>     1\n
   o> read(1) -> 1: 1