[pypy-commit] pypy py3.7: essential fast path: 0 << gigantic number == 0

cfbolz pypy.commits at gmail.com
Thu Jan 9 08:47:20 EST 2020


Author: Carl Friedrich Bolz-Tereick <cfbolz at gmx.de>
Branch: py3.7
Changeset: r98497:c7e6320ee915
Date: 2020-01-08 14:34 +0100
http://bitbucket.org/pypy/pypy/changeset/c7e6320ee915/

Log:	essential fast path: 0 << gigantic number == 0

diff --git a/pypy/objspace/std/longobject.py b/pypy/objspace/std/longobject.py
--- a/pypy/objspace/std/longobject.py
+++ b/pypy/objspace/std/longobject.py
@@ -308,6 +308,8 @@
         try:
             shift = w_other.asbigint().toint()
         except OverflowError:   # b too big
+            if self.num.sign == 0:
+                return self
             raise oefmt(space.w_OverflowError, "shift count too large")
         return W_LongObject(self.num.lshift(shift))
 
diff --git a/pypy/objspace/std/test/test_longobject.py b/pypy/objspace/std/test/test_longobject.py
--- a/pypy/objspace/std/test/test_longobject.py
+++ b/pypy/objspace/std/test/test_longobject.py
@@ -213,6 +213,7 @@
         raises(ValueError, "long(1) >> long(-1)")
         raises(ValueError, "long(1) >> -1")
         raises(OverflowError, "long(1) >> (2 ** 100)")
+        assert 0 << (1 << 1000) == 0
 
     def test_pow(self):
         long = self._long


More information about the pypy-commit mailing list