mirror of
https://github.com/python/cpython.git
synced 2024-11-24 10:24:35 +08:00
a few peephole optimizations
This commit is contained in:
parent
8d617a60b1
commit
5fe605889a
@ -133,7 +133,7 @@ lookmapping(mp, key, hash)
|
||||
and 0 < incr < ma_size and both are a function of hash */
|
||||
i = sum % mp->ma_size;
|
||||
do {
|
||||
sum = sum + sum + sum + 1;
|
||||
sum = 3*sum + 1;
|
||||
incr = sum % mp->ma_size;
|
||||
} while (incr == 0);
|
||||
for (;;) {
|
||||
|
@ -120,6 +120,7 @@ setlistitem(op, i, newitem)
|
||||
register object *newitem;
|
||||
{
|
||||
register object *olditem;
|
||||
register object **p;
|
||||
if (!is_listobject(op)) {
|
||||
XDECREF(newitem);
|
||||
err_badcall();
|
||||
@ -130,8 +131,9 @@ setlistitem(op, i, newitem)
|
||||
err_setstr(IndexError, "list assignment index out of range");
|
||||
return -1;
|
||||
}
|
||||
olditem = ((listobject *)op) -> ob_item[i];
|
||||
((listobject *)op) -> ob_item[i] = newitem;
|
||||
p = ((listobject *)op) -> ob_item + i;
|
||||
olditem = *p;
|
||||
*p = newitem;
|
||||
XDECREF(olditem);
|
||||
return 0;
|
||||
}
|
||||
|
@ -133,7 +133,7 @@ lookmapping(mp, key, hash)
|
||||
and 0 < incr < ma_size and both are a function of hash */
|
||||
i = sum % mp->ma_size;
|
||||
do {
|
||||
sum = sum + sum + sum + 1;
|
||||
sum = 3*sum + 1;
|
||||
incr = sum % mp->ma_size;
|
||||
} while (incr == 0);
|
||||
for (;;) {
|
||||
|
@ -419,7 +419,7 @@ string_hash(a)
|
||||
p = (unsigned char *) a->ob_sval;
|
||||
x = *p << 7;
|
||||
while (--len >= 0)
|
||||
x = (x + x + x) ^ *p++;
|
||||
x = (3*x) ^ *p++;
|
||||
x ^= a->ob_size;
|
||||
if (x == -1)
|
||||
x = -2;
|
||||
|
@ -119,9 +119,10 @@ int
|
||||
settupleitem(op, i, newitem)
|
||||
register object *op;
|
||||
register int i;
|
||||
register object *newitem;
|
||||
object *newitem;
|
||||
{
|
||||
register object *olditem;
|
||||
register object **p;
|
||||
if (!is_tupleobject(op)) {
|
||||
XDECREF(newitem);
|
||||
err_badcall();
|
||||
@ -132,8 +133,9 @@ settupleitem(op, i, newitem)
|
||||
err_setstr(IndexError, "tuple assignment index out of range");
|
||||
return -1;
|
||||
}
|
||||
olditem = ((tupleobject *)op) -> ob_item[i];
|
||||
((tupleobject *)op) -> ob_item[i] = newitem;
|
||||
p = ((tupleobject *)op) -> ob_item + i;
|
||||
olditem = *p;
|
||||
*p = newitem;
|
||||
XDECREF(olditem);
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user