]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
a few peephole optimizations
authorGuido van Rossum <guido@python.org>
Thu, 9 Mar 1995 12:12:50 +0000 (12:12 +0000)
committerGuido van Rossum <guido@python.org>
Thu, 9 Mar 1995 12:12:50 +0000 (12:12 +0000)
Objects/dictobject.c
Objects/listobject.c
Objects/mappingobject.c
Objects/stringobject.c
Objects/tupleobject.c

index d74e74ffd1b9e25c3b3a28814f02fe197377be7e..11d344a9742ed99933f3d5d31cafebfcdf2cbfc0 100644 (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 (;;) {
index a367ed1a270e7a6c729f3cc61ca5e1aa7dd2035d..44003bc9ce002f089783f37eec9444bc50f185d7 100644 (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;
 }
index d74e74ffd1b9e25c3b3a28814f02fe197377be7e..11d344a9742ed99933f3d5d31cafebfcdf2cbfc0 100644 (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 (;;) {
index cb76d77f68f5bcf85ea4b820b09fbed1d6cb5d0c..b09fc2546df93e793d214de625e86c89b02a78b1 100644 (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;
index 1e5ea1392f73ac3cc6e0c52b91b1890e784a90a6..69c4f95937629e7b9c8879c6948d64a395c9e7b3 100644 (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;
 }