summaryrefslogtreecommitdiffstats
path: root/Objects/listobject.c
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1996-08-09 20:51:27 (GMT)
committerGuido van Rossum <guido@python.org>1996-08-09 20:51:27 (GMT)
commit929f1b83ea8810c66a5e1e9f162d8680463abb0f (patch)
tree491082cc059c84f82624411b3a7d3f52169082f5 /Objects/listobject.c
parent86c04c252b9ec1cb682d9fd52bdd48b61434c4b3 (diff)
downloadcpython-929f1b83ea8810c66a5e1e9f162d8680463abb0f.zip
cpython-929f1b83ea8810c66a5e1e9f162d8680463abb0f.tar.gz
cpython-929f1b83ea8810c66a5e1e9f162d8680463abb0f.tar.bz2
Use pre-created string objects for most common exceptions
(especially IndexError which is caught by 'for')
Diffstat (limited to 'Objects/listobject.c')
-rw-r--r--Objects/listobject.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/Objects/listobject.c b/Objects/listobject.c
index b3e3378..17307f7 100644
--- a/Objects/listobject.c
+++ b/Objects/listobject.c
@@ -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]);