[pypy-commit] pypy default: remove code duplication in floordiv

cfbolz pypy.commits at gmail.com
Mon Feb 5 07:10:14 EST 2018


Author: Carl Friedrich Bolz-Tereick <cfbolz at gmx.de>
Branch: 
Changeset: r93763:864485a54ece
Date: 2018-02-05 12:27 +0100
http://bitbucket.org/pypy/pypy/changeset/864485a54ece/

Log:	remove code duplication in floordiv

diff --git a/rpython/rlib/rbigint.py b/rpython/rlib/rbigint.py
--- a/rpython/rlib/rbigint.py
+++ b/rpython/rlib/rbigint.py
@@ -762,12 +762,10 @@
 
     @jit.elidable
     def floordiv(self, other):
-        if self.sign == 1 and other.numdigits() == 1 and other.sign == 1:
-            digit = other.digit(0)
-            if digit == 1:
-                return rbigint(self._digits[:self.size], 1, self.size)
-            elif digit and digit & (digit - 1) == 0:
-                return self.rshift(ptwotable[digit])
+        if other.numdigits() == 1:
+            otherint = other.digit(0) * other.sign
+            assert int_in_valid_range(otherint)
+            return self.int_floordiv(otherint)
 
         div, mod = _divrem(self, other)
         if mod.sign * other.sign == -1:


More information about the pypy-commit mailing list