mirror of
https://github.com/python/cpython.git
synced 2025-11-26 21:33:10 +00:00
Use pre-created string objects for most common exceptions
(especially IndexError which is caught by 'for')
This commit is contained in:
parent
86c04c252b
commit
929f1b83ea
1 changed files with 8 additions and 2 deletions
|
|
@ -97,6 +97,8 @@ getlistsize(op)
|
||||||
return ((listobject *)op) -> ob_size;
|
return ((listobject *)op) -> ob_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static object *indexerr;
|
||||||
|
|
||||||
object *
|
object *
|
||||||
getlistitem(op, i)
|
getlistitem(op, i)
|
||||||
object *op;
|
object *op;
|
||||||
|
|
@ -107,7 +109,9 @@ getlistitem(op, i)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (i < 0 || i >= ((listobject *)op) -> ob_size) {
|
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 NULL;
|
||||||
}
|
}
|
||||||
return ((listobject *)op) -> ob_item[i];
|
return ((listobject *)op) -> ob_item[i];
|
||||||
|
|
@ -274,7 +278,9 @@ list_item(a, i)
|
||||||
int i;
|
int i;
|
||||||
{
|
{
|
||||||
if (i < 0 || i >= a->ob_size) {
|
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;
|
return NULL;
|
||||||
}
|
}
|
||||||
INCREF(a->ob_item[i]);
|
INCREF(a->ob_item[i]);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue