py-api: store frequently used strings as unicode PyObject's to avoid creating/distroy...
[blender.git] / source / blender / python / intern / bpy_rna.c
index 00325446e614ec415a6aaf9a2fb9b95e04e467c9..16f4de700f63b6913782c8fe5aa29359726a62fd 100644 (file)
@@ -39,6 +39,7 @@
 #include "bpy_props.h"
 #include "bpy_util.h"
 #include "bpy_rna_callback.h"
+#include "bpy_intern_string.h"
 
 #ifdef USE_PYRNA_INVALIDATE_WEAKREF
 #include "MEM_guardedalloc.h"
@@ -5217,7 +5218,7 @@ static void pyrna_subtype_set_rna(PyObject *newclass, StructRNA *srna)
        item= pyrna_struct_CreatePyObject(&ptr);
 
        /* note, must set the class not the __dict__ else the internal slots are not updated correctly */
-       PyObject_SetAttrString(newclass, "bl_rna", item);
+       PyObject_SetAttr(newclass, bpy_intern_str_bl_rna, item);
        Py_DECREF(item);
 
        /* done with rna instance */
@@ -5279,7 +5280,7 @@ static PyObject* pyrna_srna_ExternalType(StructRNA *srna)
                //PyObject *slots= PyObject_GetAttrString(newclass, "__slots__"); // cant do this because it gets superclasses values!
                //PyObject *bases= PyObject_GetAttrString(newclass, "__bases__"); // can do this but faster not to.
                PyObject *bases= ((PyTypeObject *)newclass)->tp_bases;
-               PyObject *slots= PyDict_GetItemString(((PyTypeObject *)newclass)->tp_dict, "__slots__");
+               PyObject *slots= PyDict_GetItem(((PyTypeObject *)newclass)->tp_dict, bpy_intern_str___slots__);
 
                if(slots==NULL) {
                        fprintf(stderr, "pyrna_srna_ExternalType: expected class '%s' to have __slots__ defined\n\nSee bpy_types.py\n", idname);
@@ -5649,7 +5650,7 @@ StructRNA *pyrna_struct_as_srna(PyObject *self, int parent, const char *error_pr
 
        /* ack, PyObject_GetAttrString wont look up this types tp_dict first :/ */
        if(PyType_Check(self)) {
-               py_srna= (BPy_StructRNA *)PyDict_GetItemString(((PyTypeObject *)self)->tp_dict, "bl_rna");
+               py_srna= (BPy_StructRNA *)PyDict_GetItem(((PyTypeObject *)self)->tp_dict, bpy_intern_str_bl_rna);
                Py_XINCREF(py_srna);
        }
 
@@ -5657,7 +5658,7 @@ StructRNA *pyrna_struct_as_srna(PyObject *self, int parent, const char *error_pr
                /* be very careful with this since it will return a parent classes srna.
                 * modifying this will do confusing stuff! */
                if(py_srna==NULL)
-                       py_srna= (BPy_StructRNA*)PyObject_GetAttrString(self, "bl_rna");
+                       py_srna= (BPy_StructRNA*)PyObject_GetAttr(self, bpy_intern_str_bl_rna);
        }
 
        if(py_srna==NULL) {
@@ -5747,7 +5748,7 @@ static int deferred_register_prop(StructRNA *srna, PyObject *key, PyObject *item
                        py_srna_cobject= PyCapsule_New(srna, NULL, NULL);
 
                        /* not 100% nice :/, modifies the dict passed, should be ok */
-                       PyDict_SetItemString(py_kw, "attr", key);
+                       PyDict_SetItem(py_kw, bpy_intern_str_attr, key);
 
                        args_fake= PyTuple_New(1);
                        PyTuple_SET_ITEM(args_fake, 0, py_srna_cobject);
@@ -5794,7 +5795,7 @@ static int pyrna_deferred_register_props(StructRNA *srna, PyObject *class_dict)
        /* in both cases PyDict_CheckExact(class_dict) will be true even
         * though Operators have a metaclass dict namespace */
 
-       if((order= PyDict_GetItemString(class_dict, "order")) && PyList_CheckExact(order)) {
+       if((order= PyDict_GetItem(class_dict, bpy_intern_str_order)) && PyList_CheckExact(order)) {
                for(pos= 0; pos<PyList_GET_SIZE(order); pos++) {
                        key= PyList_GET_ITEM(order, pos);
                        item= PyDict_GetItem(class_dict, key);
@@ -6299,7 +6300,7 @@ static void bpy_class_free(void *pyob_ptr)
        // PyDict_Clear(((PyTypeObject*)self)->tp_dict);
        //
        // remove the rna attribute instead.
-       PyDict_DelItemString(((PyTypeObject *)self)->tp_dict, "bl_rna");
+       PyDict_DelItem(((PyTypeObject *)self)->tp_dict, bpy_intern_str_bl_rna);
        if(PyErr_Occurred())
                PyErr_Clear();
 
@@ -6405,7 +6406,7 @@ static PyObject *pyrna_register_class(PyObject *UNUSED(self), PyObject *py_class
        const char *identifier;
        PyObject *py_cls_meth;
 
-       if(PyDict_GetItemString(((PyTypeObject*)py_class)->tp_dict, "bl_rna")) {
+       if(PyDict_GetItem(((PyTypeObject*)py_class)->tp_dict, bpy_intern_str_bl_rna)) {
                PyErr_SetString(PyExc_AttributeError, "register_class(...): already registered as a subclass");
                return NULL;
        }
@@ -6470,7 +6471,7 @@ static PyObject *pyrna_register_class(PyObject *UNUSED(self), PyObject *py_class
                return NULL;
 
        /* call classed register method () */
-       py_cls_meth= PyObject_GetAttrString(py_class, "register");
+       py_cls_meth= PyObject_GetAttr(py_class, bpy_intern_str_register);
        if(py_cls_meth == NULL) {
                PyErr_Clear();
        }
@@ -6528,7 +6529,7 @@ static PyObject *pyrna_unregister_class(PyObject *UNUSED(self), PyObject *py_cla
        StructRNA *srna;
        PyObject *py_cls_meth;
 
-       /*if(PyDict_GetItemString(((PyTypeObject*)py_class)->tp_dict, "bl_rna")==NULL) {
+       /*if(PyDict_GetItem(((PyTypeObject*)py_class)->tp_dict, bpy_intern_str_bl_rna)==NULL) {
                PWM_cursor_wait(0);
                PyErr_SetString(PyExc_ValueError, "unregister_class(): not a registered as a subclass");
                return NULL;
@@ -6547,7 +6548,7 @@ static PyObject *pyrna_unregister_class(PyObject *UNUSED(self), PyObject *py_cla
        }
 
        /* call classed unregister method */
-       py_cls_meth= PyObject_GetAttrString(py_class, "unregister");
+       py_cls_meth= PyObject_GetAttr(py_class, bpy_intern_str_unregister);
        if(py_cls_meth == NULL) {
                PyErr_Clear();
        }
@@ -6597,7 +6598,7 @@ static PyObject *pyrna_unregister_class(PyObject *UNUSED(self), PyObject *py_cla
        /* call unregister */
        unreg(CTX_data_main(C), srna); /* calls bpy_class_free, this decref's py_class */
 
-       PyDict_DelItemString(((PyTypeObject *)py_class)->tp_dict, "bl_rna");
+       PyDict_DelItem(((PyTypeObject *)py_class)->tp_dict, bpy_intern_str_bl_rna);
        if(PyErr_Occurred())
                PyErr_Clear(); //return NULL;