mirror of
https://github.com/python/cpython.git
synced 2025-09-27 10:50:04 +00:00
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:
parent
2516b39dd3
commit
ba71a247ac
1 changed files with 9 additions and 0 deletions
|
@ -1223,6 +1223,15 @@ long_mul(a, b)
|
||||||
|
|
||||||
size_a = ABS(a->ob_size);
|
size_a = ABS(a->ob_size);
|
||||||
size_b = ABS(b->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);
|
z = _PyLong_New(size_a + size_b);
|
||||||
if (z == NULL)
|
if (z == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue