a few peephole optimizations

This commit is contained in:
Guido van Rossum 1995-03-09 12:12:50 +00:00
parent 8d617a60b1
commit 5fe605889a
5 changed files with 12 additions and 8 deletions

View File

@ -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 (;;) {

View File

@ -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;
}

View File

@ -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 (;;) {

View File

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

View File

@ -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;
}