mirror of
https://github.com/python/cpython.git
synced 2025-10-17 12:18:23 +00:00
Optimized stringitem.
This commit is contained in:
parent
bf109736d9
commit
b6a6bdc7db
1 changed files with 13 additions and 1 deletions
|
@ -246,11 +246,23 @@ stringitem(a, i)
|
||||||
stringobject *a;
|
stringobject *a;
|
||||||
register int i;
|
register int i;
|
||||||
{
|
{
|
||||||
|
/* This is optimized since this is a common operation! */
|
||||||
|
|
||||||
|
register stringobject *op;
|
||||||
if (i < 0 || i >= a->ob_size) {
|
if (i < 0 || i >= a->ob_size) {
|
||||||
err_setstr(IndexError, "string index out of range");
|
err_setstr(IndexError, "string index out of range");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
return stringslice(a, i, i+1);
|
op = (stringobject *)
|
||||||
|
malloc(sizeof(stringobject) + sizeof(char));
|
||||||
|
if (op == NULL)
|
||||||
|
return err_nomem();
|
||||||
|
NEWREF(op);
|
||||||
|
op->ob_type = &Stringtype;
|
||||||
|
op->ob_size = 1;
|
||||||
|
op->ob_sval[0] = a->ob_sval[i];
|
||||||
|
op->ob_sval[1] = '\0';
|
||||||
|
return (object *) op;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue