]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Optimized stringitem.
authorGuido van Rossum <guido@python.org>
Wed, 6 Mar 1991 13:15:02 +0000 (13:15 +0000)
committerGuido van Rossum <guido@python.org>
Wed, 6 Mar 1991 13:15:02 +0000 (13:15 +0000)
Objects/stringobject.c

index cb04d949a543d7f5c930258a7dce0610c3d3478b..9b11f9279dca1e015335a81526b18d1647ad52a3 100644 (file)
@@ -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