Mercurial > cpython-lru_cache-weakref
diff Objects/classobject.c @ 5008:f55e82e1e565 legacy-trunk
Intern the various string objects created to speed up lookups.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Sat, 18 Jan 1997 07:59:12 +0000 |
| parents | 4f644ecc5bac |
| children | d1447950fa04 |
line wrap: on
line diff
--- a/Objects/classobject.c Sat Jan 18 07:58:41 1997 +0000 +++ b/Objects/classobject.c Sat Jan 18 07:59:12 1997 +0000 @@ -52,7 +52,7 @@ static object *getattrstr, *setattrstr, *delattrstr; static object *docstr; if (docstr == NULL) { - docstr= newstringobject("__doc__"); + docstr= PyString_InternFromString("__doc__"); if (docstr == NULL) return NULL; } @@ -78,9 +78,9 @@ XINCREF(name); op->cl_name = name; if (getattrstr == NULL) { - getattrstr = newstringobject("__getattr__"); - setattrstr = newstringobject("__setattr__"); - delattrstr = newstringobject("__delattr__"); + getattrstr = PyString_InternFromString("__getattr__"); + setattrstr = PyString_InternFromString("__setattr__"); + delattrstr = PyString_InternFromString("__delattr__"); } op->cl_getattr = class_lookup(op, getattrstr, &dummy); op->cl_setattr = class_lookup(op, setattrstr, &dummy); @@ -349,7 +349,7 @@ return NULL; } if (initstr == NULL) - initstr = newstringobject("__init__"); + initstr = PyString_InternFromString("__init__"); init = instance_getattr1(inst, initstr); if (init == NULL) { err_clear(); @@ -408,7 +408,7 @@ #endif /* !Py_TRACE_REFS */ err_fetch(&error_type, &error_value, &error_traceback); if (delstr == NULL) - delstr = newstringobject("__del__"); + delstr = PyString_InternFromString("__del__"); if ((del = instance_getattr1(inst, delstr)) != NULL) { object *res = call_object(del, (object *)NULL); if (res == NULL) { @@ -610,7 +610,7 @@ static object *reprstr; if (reprstr == NULL) - reprstr = newstringobject("__repr__"); + reprstr = PyString_InternFromString("__repr__"); func = instance_getattr(inst, reprstr); if (func == NULL) { char buf[140]; @@ -667,14 +667,14 @@ static object *hashstr, *cmpstr; if (hashstr == NULL) - hashstr = newstringobject("__hash__"); + hashstr = PyString_InternFromString("__hash__"); func = instance_getattr(inst, hashstr); if (func == NULL) { /* If there is no __cmp__ method, we hash on the address. If a __cmp__ method exists, there must be a __hash__. */ err_clear(); if (cmpstr == NULL) - cmpstr = newstringobject("__cmp__"); + cmpstr = PyString_InternFromString("__cmp__"); func = instance_getattr(inst, cmpstr); if (func == NULL) { err_clear(); @@ -714,7 +714,7 @@ int outcome; if (lenstr == NULL) - lenstr = newstringobject("__len__"); + lenstr = PyString_InternFromString("__len__"); func = instance_getattr(inst, lenstr); if (func == NULL) return -1; @@ -745,7 +745,7 @@ object *res; if (getitemstr == NULL) - getitemstr = newstringobject("__getitem__"); + getitemstr = PyString_InternFromString("__getitem__"); func = instance_getattr(inst, getitemstr); if (func == NULL) return NULL; @@ -772,12 +772,12 @@ if (value == NULL) { if (delitemstr == NULL) - delitemstr = newstringobject("__delitem__"); + delitemstr = PyString_InternFromString("__delitem__"); func = instance_getattr(inst, delitemstr); } else { if (setitemstr == NULL) - setitemstr = newstringobject("__setitem__"); + setitemstr = PyString_InternFromString("__setitem__"); func = instance_getattr(inst, setitemstr); } if (func == NULL) @@ -813,7 +813,7 @@ object *func, *arg, *res; if (getitemstr == NULL) - getitemstr = newstringobject("__getitem__"); + getitemstr = PyString_InternFromString("__getitem__"); func = instance_getattr(inst, getitemstr); if (func == NULL) return NULL; @@ -837,7 +837,7 @@ static object *getslicestr; if (getslicestr == NULL) - getslicestr = newstringobject("__getslice__"); + getslicestr = PyString_InternFromString("__getslice__"); func = instance_getattr(inst, getslicestr); if (func == NULL) return NULL; @@ -862,12 +862,12 @@ if (item == NULL) { if (delitemstr == NULL) - delitemstr = newstringobject("__delitem__"); + delitemstr = PyString_InternFromString("__delitem__"); func = instance_getattr(inst, delitemstr); } else { if (setitemstr == NULL) - setitemstr = newstringobject("__setitem__"); + setitemstr = PyString_InternFromString("__setitem__"); func = instance_getattr(inst, setitemstr); } if (func == NULL) @@ -900,12 +900,12 @@ if (value == NULL) { if (delslicestr == NULL) - delslicestr = newstringobject("__delslice__"); + delslicestr = PyString_InternFromString("__delslice__"); func = instance_getattr(inst, delslicestr); } else { if (setslicestr == NULL) - setslicestr = newstringobject("__setslice__"); + setslicestr = PyString_InternFromString("__setslice__"); func = instance_getattr(inst, setslicestr); } if (func == NULL) @@ -1006,7 +1006,7 @@ if (!is_instanceobject(v)) return 1; if (coerce_obj == NULL) { - coerce_obj = newstringobject("__coerce__"); + coerce_obj = PyString_InternFromString("__coerce__"); if (coerce_obj == NULL) return -1; } @@ -1083,7 +1083,7 @@ object *coerced; if (coerce_obj == NULL) { - coerce_obj = newstringobject("__coerce__"); + coerce_obj = PyString_InternFromString("__coerce__"); if (coerce_obj == NULL) return -1; } @@ -1132,7 +1132,7 @@ #define UNARY(funcname, methodname) \ static object *funcname(self) instanceobject *self; { \ static object *o; \ - if (o == NULL) o = newstringobject(methodname); \ + if (o == NULL) o = PyString_InternFromString(methodname); \ return generic_unary_op(self, o); \ } @@ -1149,11 +1149,11 @@ static object *nonzerostr; if (nonzerostr == NULL) - nonzerostr = newstringobject("__nonzero__"); + nonzerostr = PyString_InternFromString("__nonzero__"); if ((func = instance_getattr(self, nonzerostr)) == NULL) { err_clear(); if (lenstr == NULL) - lenstr = newstringobject("__len__"); + lenstr = PyString_InternFromString("__len__"); if ((func = instance_getattr(self, lenstr)) == NULL) { err_clear(); /* Fall back to the default behavior: @@ -1200,7 +1200,7 @@ static object *powstr; if (powstr == NULL) - powstr = newstringobject("__pow__"); + powstr = PyString_InternFromString("__pow__"); func = getattro(v, powstr); if (func == NULL) return NULL;
