Commits

Armin Rigo committed d7d63ba

(austiine, arigo)

issue1618: this should fix the performance degradation of
'pow(huge, smallish, smallish)'. Note that CPython could
use the same too.

  • Participants
  • Parent commits 0026aa8

Comments (0)

Files changed (1)

rpython/rlib/rbigint.py

             # if base < 0:
             #     base = base % modulus
             # Having the base positive just makes things easier.
-            if a.sign < 0:
+            # As a (very good) optimization, we also reduce 'base' here
+            # if it is much bigger than the modulus.
+            if a.sign < 0 or a.numdigits() > c.numdigits():
                 a = a.mod(c)
 
         elif b.sign == 0: