diff options
author | Guido van Rossum <guido@python.org> | 1991-03-06 13:15:02 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1991-03-06 13:15:02 (GMT) |
commit | b6a6bdc7db54c684646f3cc3c537e8c62293986d (patch) | |
tree | cc4dc5645edc52b1359ae8eef2af71f8fd3e34cd /Objects | |
parent | bf109736d92d5d0df8992466e19c4403179a42d8 (diff) | |
download | cpython-b6a6bdc7db54c684646f3cc3c537e8c62293986d.zip cpython-b6a6bdc7db54c684646f3cc3c537e8c62293986d.tar.gz cpython-b6a6bdc7db54c684646f3cc3c537e8c62293986d.tar.bz2 |
Optimized stringitem.
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/stringobject.c | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/Objects/stringobject.c b/Objects/stringobject.c index cb04d94..9b11f92 100644 --- a/Objects/stringobject.c +++ b/Objects/stringobject.c @@ -246,11 +246,23 @@ stringitem(a, i) stringobject *a; register int i; { + /* This is optimized since this is a common operation! */ + + register stringobject *op; if (i < 0 || i >= a->ob_size) { err_setstr(IndexError, "string index out of range"); 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 |