summaryrefslogtreecommitdiffstats
path: root/Objects/longobject.c
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2000-04-10 17:31:58 (GMT)
committerGuido van Rossum <guido@python.org>2000-04-10 17:31:58 (GMT)
commitba71a247acc7cac07a75d79ff087b29b56ee0b55 (patch)
treed794ad5a99944f1e5bee9f9341c31ca263baad0f /Objects/longobject.c
parent2516b39dd35a3e0d815e25ee652cea6c90cc5b28 (diff)
downloadcpython-ba71a247acc7cac07a75d79ff087b29b56ee0b55.zip
cpython-ba71a247acc7cac07a75d79ff087b29b56ee0b55.tar.gz
cpython-ba71a247acc7cac07a75d79ff087b29b56ee0b55.tar.bz2
Simple optimization by Christian Tismer, who gives credit to Lenny
Kneler for reporting this issue: long_mult() is faster when the smaller argument is on the left. Swap the arguments accordingly.
Diffstat (limited to 'Objects/longobject.c')
-rw-r--r--Objects/longobject.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/Objects/longobject.c b/Objects/longobject.c
index d5c2f5f..a9ce6f3 100644
--- a/Objects/longobject.c
+++ b/Objects/longobject.c
@@ -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;