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.
This commit is contained in:
Guido van Rossum 2000-04-10 17:31:58 +00:00
parent 2516b39dd3
commit ba71a247ac
1 changed files with 9 additions and 0 deletions

View 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;