]> granicus.if.org Git - python/commitdiff
Use pre-created string objects for most common exceptions
authorGuido van Rossum <guido@python.org>
Fri, 9 Aug 1996 20:51:27 +0000 (20:51 +0000)
committerGuido van Rossum <guido@python.org>
Fri, 9 Aug 1996 20:51:27 +0000 (20:51 +0000)
(especially IndexError which is caught by 'for')

Objects/listobject.c

index b3e3378c887ea33d80cf2da0f98c171022ed0cc3..17307f7e17f18261e5af4bae806c48368d9c40fe 100644 (file)
@@ -97,6 +97,8 @@ getlistsize(op)
                return ((listobject *)op) -> ob_size;
 }
 
+static object *indexerr;
+
 object *
 getlistitem(op, i)
        object *op;
@@ -107,7 +109,9 @@ getlistitem(op, i)
                return NULL;
        }
        if (i < 0 || i >= ((listobject *)op) -> ob_size) {
-               err_setstr(IndexError, "list index out of range");
+               if (indexerr == NULL)
+                       indexerr = newstringobject("list index out of range");
+               err_setval(IndexError, indexerr);
                return NULL;
        }
        return ((listobject *)op) -> ob_item[i];
@@ -274,7 +278,9 @@ list_item(a, i)
        int i;
 {
        if (i < 0 || i >= a->ob_size) {
-               err_setstr(IndexError, "list index out of range");
+               if (indexerr == NULL)
+                       indexerr = newstringobject("list index out of range");
+               err_setval(IndexError, indexerr);
                return NULL;
        }
        INCREF(a->ob_item[i]);