Author: Philip Jenvey <[email protected]>
Branch: remove-intlong-smm
Changeset: r69231:bb83564f9dbd
Date: 2014-02-20 17:20 -0800
http://bitbucket.org/pypy/pypy/changeset/bb83564f9dbd/

Log:    apply optimized_int_add to INPLACE_ADD and add a similar opt. for
        subtraction. these may prove useful for interpreted mode now that we
        lack mulitmethod shortcuts

diff --git a/pypy/objspace/std/frame.py b/pypy/objspace/std/frame.py
--- a/pypy/objspace/std/frame.py
+++ b/pypy/objspace/std/frame.py
@@ -36,6 +36,22 @@
     self.pushvalue(w_result)
 
 
+def int_BINARY_SUBTRACT(self, oparg, next_instr):
+    space = self.space
+    w_2 = self.popvalue()
+    w_1 = self.popvalue()
+    if type(w_1) is W_IntObject and type(w_2) is W_IntObject:
+        try:
+            z = ovfcheck(w_1.intval - w_2.intval)
+        except OverflowError:
+            w_result = w_1.descr_sub(space, w_2)
+        else:
+            w_result = space.newint(z)
+    else:
+        w_result = space.sub(w_1, w_2)
+    self.pushvalue(w_result)
+
+
 def list_BINARY_SUBSCR(self, oparg, next_instr):
     space = self.space
     w_2 = self.popvalue()
@@ -56,6 +72,9 @@
         pass
     if space.config.objspace.std.optimized_int_add:
         StdObjSpaceFrame.BINARY_ADD = int_BINARY_ADD
+        StdObjSpaceFrame.INPLACE_ADD = int_BINARY_ADD
+        StdObjSpaceFrame.BINARY_SUB = int_BINARY_SUBTRACT
+        StdObjSpaceFrame.INPLACE_SUBTRACT = int_BINARY_SUBTRACT
     if space.config.objspace.std.optimized_list_getitem:
         StdObjSpaceFrame.BINARY_SUBSCR = list_BINARY_SUBSCR
     from pypy.objspace.std.callmethod import LOOKUP_METHOD, CALL_METHOD
diff --git a/pypy/objspace/std/test/test_intobject.py 
b/pypy/objspace/std/test/test_intobject.py
--- a/pypy/objspace/std/test/test_intobject.py
+++ b/pypy/objspace/std/test/test_intobject.py
@@ -310,6 +310,13 @@
                 return 42
         assert I(1).conjugate() == 1
 
+    def test_inplace(self):
+        a = 1
+        a += 1
+        assert a == 2
+        a -= 1
+        assert a == 1
+
     def test_trunc(self):
         import math
         assert math.trunc(1) == 1
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to