summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2002-08-08 21:57:53 (GMT)
committerGuido van Rossum <guido@python.org>2002-08-08 21:57:53 (GMT)
commit7bed213224508a5f33ed6d88b48017eea803f499 (patch)
tree11a94b44d5e7ea821eba7ebc82451c12cbffc6dc
parent617e2305ee5d620409aa4679dccc39323a06f7a1 (diff)
downloadcpython-7bed213224508a5f33ed6d88b48017eea803f499.zip
cpython-7bed213224508a5f33ed6d88b48017eea803f499.tar.gz
cpython-7bed213224508a5f33ed6d88b48017eea803f499.tar.bz2
Significant speedup in new-style object creation: in slot_tp_new(),
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).
-rw-r--r--Objects/typeobject.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/Objects/typeobject.c b/Objects/typeobject.c
index edf4e70..f46734b 100644
--- a/Objects/typeobject.c
+++ b/Objects/typeobject.c
@@ -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));