]> granicus.if.org Git - python/commitdiff
Simple optimization by Christian Tismer, who gives credit to Lenny
authorGuido van Rossum <guido@python.org>
Mon, 10 Apr 2000 17:31:58 +0000 (17:31 +0000)
committerGuido van Rossum <guido@python.org>
Mon, 10 Apr 2000 17:31:58 +0000 (17:31 +0000)
Kneler for reporting this issue: long_mult() is faster when the
smaller argument is on the left.  Swap the arguments accordingly.

Objects/longobject.c

index d5c2f5f767493ac4dbe33bce92108f97f0d29307..a9ce6f3c3b864f50de2c8fd6fa49fc8277b7e4ea 100644 (file)
@@ -1223,6 +1223,15 @@ long_mul(a, b)
        
        size_a = ABS(a->ob_size);
        size_b = ABS(b->ob_size);
+       if (size_a > size_b) {
+               /* we are faster with the small object on the left */
+               int hold_sa = size_a;
+               PyLongObject *hold_a = a;
+               size_a = size_b;
+               size_b = hold_sa;
+               a = b;
+               b = hold_a;
+       }
        z = _PyLong_New(size_a + size_b);
        if (z == NULL)
                return NULL;