1. Pypy
  2. Untitled project
  3. pypy

Commits

Philip Jenvey  committed 88b0527

more don't bother w/ OverflowErrors unless it's necessary

  • Participants
  • Parent commits bede337
  • Branches remove-intlong-smm

Comments (0)

Files changed (2)

File pypy/objspace/std/intobject.py

View file
  • Ignore whitespace
     descr_or, descr_ror = _make_generic_descr_binop('or', ovf=False)
     descr_xor, descr_rxor = _make_generic_descr_binop('xor', ovf=False)
 
-    def _make_descr_binop(func):
+    def _make_descr_binop(func, ovf=True):
         opname = func.__name__[1:]
         oper = BINARY_OPS.get(opname)
         if oper == '%':
         def descr_binop(self, space, w_other):
             if not isinstance(w_other, W_AbstractIntObject):
                 return space.w_NotImplemented
-            try:
+            if ovf:
+                try:
+                    return func(self, space, w_other)
+                except OverflowError:
+                    return _ovf2long(space, opname, self, w_other)
+            else:
                 return func(self, space, w_other)
-            except OverflowError:
-                return _ovf2long(space, opname, self, w_other)
         descr_binop.__doc__ = "x.__%s__(y) <==> %s" % (opname,
                                                        oper % ('x', 'y'))
 
         def descr_rbinop(self, space, w_other):
             if not isinstance(w_other, W_AbstractIntObject):
                 return space.w_NotImplemented
-            try:
+            if ovf:
+                try:
+                    return func(w_other, space, self)
+                except OverflowError:
+                    return _ovf2long(space, opname, w_other, self)
+            else:
                 return func(w_other, space, self)
-            except OverflowError:
-                return _ovf2long(space, opname, w_other, self)
         descr_rbinop.__doc__ = "x.__r%s__(y) <==> %s" % (opname,
                                                          oper % ('y', 'x'))
 
             raise operationerrfmt(space.w_ZeroDivisionError,
                                   "division by zero")
         return space.wrap(x / y)
-    descr_truediv, descr_rtruediv = _make_descr_binop(_truediv)
+    descr_truediv, descr_rtruediv = _make_descr_binop(_truediv, ovf=False)
 
     def _mod(self, space, w_other):
         x = space.int_w(self)
         else:
             a = a >> b
         return wrapint(space, a)
-    descr_rshift, descr_rrshift = _make_descr_binop(_rshift)
+    descr_rshift, descr_rrshift = _make_descr_binop(_rshift, ovf=False)
 
 
 class W_IntObject(W_AbstractIntObject):

File pypy/objspace/std/smalllongobject.py

View file
  • Ignore whitespace
     descr_gt = _make_descr_cmp('gt')
     descr_ge = _make_descr_cmp('ge')
 
-    def _make_descr_binop(func):
+    def _make_descr_binop(func, ovf=True):
         opname = func.__name__[1:]
         descr_name, descr_rname = 'descr_' + opname, 'descr_r' + opname
         long_op = getattr(W_LongObject, descr_name)
                 self = _small2long(space, self)
                 return long_op(self, space, w_other)
 
-            try:
+            if ovf:
+                try:
+                    return func(self, space, w_other)
+                except OverflowError:
+                    self = _small2long(space, self)
+                    w_other = _small2long(space, w_other)
+                    return long_op(self, space, w_other)
+            else:
                 return func(self, space, w_other)
-            except OverflowError:
-                self = _small2long(space, self)
-                w_other = _small2long(space, w_other)
-                return long_op(self, space, w_other)
 
         if opname in COMMUTATIVE_OPS:
             descr_rbinop = func_with_new_name(descr_binop, descr_rname)
                     self = _small2long(space, self)
                     return long_rop(self, space, w_other)
 
-                try:
+                if ovf:
+                    try:
+                        return func(w_other, space, self)
+                    except OverflowError:
+                        self = _small2long(space, self)
+                        w_other = _small2long(space, w_other)
+                        return long_rop(self, space, w_other)
+                else:
                     return func(w_other, space, self)
-                except OverflowError:
-                    self = _small2long(space, self)
-                    w_other = _small2long(space, w_other)
-                    return long_rop(self, space, w_other)
 
         return descr_binop, descr_rbinop
 
         else:
             a = a >> b
         return W_SmallLongObject(a)
-    descr_rshift, descr_rrshift = _make_descr_binop(_rshift)
+    descr_rshift, descr_rrshift = _make_descr_binop(_rshift, ovf=False)
 
     def _and(self, space, w_other):
         a = self.longlong
         b = w_other.longlong
         res = a & b
         return W_SmallLongObject(res)
-    descr_and, descr_rand = _make_descr_binop(_and)
+    descr_and, descr_rand = _make_descr_binop(_and, ovf=False)
 
     def _xor(self, space, w_other):
         a = self.longlong
         b = w_other.longlong
         res = a ^ b
         return W_SmallLongObject(res)
-    descr_xor, descr_rxor = _make_descr_binop(_xor)
+    descr_xor, descr_rxor = _make_descr_binop(_xor, ovf=False)
 
     def _or(self, space, w_other):
         a = self.longlong
         b = w_other.longlong
         res = a | b
         return W_SmallLongObject(res)
-    descr_or, descr_ror = _make_descr_binop(_or)
+    descr_or, descr_ror = _make_descr_binop(_or, ovf=False)
 
 
 # ____________________________________________________________