]> granicus.if.org Git - python/commitdiff
Significant speedup in new-style object creation: in slot_tp_new(),
authorGuido van Rossum <guido@python.org>
Thu, 8 Aug 2002 21:57:53 +0000 (21:57 +0000)
committerGuido van Rossum <guido@python.org>
Thu, 8 Aug 2002 21:57:53 +0000 (21:57 +0000)
intern the string "__new__" so we can call PyObject_GetAttr() rather
than PyObject_GetAttrString().  (Though it's a mystery why slot_tp_new
is being called when a class doesn't define __new__.  I'll look into
that tomorrow.)

2.2 backport candidate (but I won't do it).

Objects/typeobject.c

index edf4e7044d6d66e75ccf10c91c387baadfa6dc56..f46734b108e8ec1d6d1de32348246ebe5e724dad 100644 (file)
@@ -3641,10 +3641,17 @@ slot_tp_init(PyObject *self, PyObject *args, PyObject *kwds)
 static PyObject *
 slot_tp_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
 {
-       PyObject *func = PyObject_GetAttrString((PyObject *)type, "__new__");
+       static PyObject *new_str;
+       PyObject *func;
        PyObject *newargs, *x;
        int i, n;
 
+       if (new_str == NULL) {
+               new_str = PyString_InternFromString("__new__");
+               if (new_str == NULL)
+                       return NULL;
+       }
+       func = PyObject_GetAttr((PyObject *)type, new_str);
        if (func == NULL)
                return NULL;
        assert(PyTuple_Check(args));