PyAPI: use instancing when supported
authorCampbell Barton <ideasman42@gmail.com>
Thu, 20 Jul 2017 14:45:35 +0000 (00:45 +1000)
committerCampbell Barton <ideasman42@gmail.com>
Thu, 20 Jul 2017 14:50:18 +0000 (00:50 +1000)
This means when a new data-type is returned it will use the same
instance as the previously created one (if it exists).

source/blender/python/intern/bpy_rna.c

index 51e179fb317a23222d345ce9973689a204a1d4a6..ca1e74ce28eef71707b8ca91eb0ca53d7a9177ed 100644 (file)
@@ -6658,6 +6658,17 @@ PyObject *pyrna_struct_CreatePyObject(PointerRNA *ptr)
                Py_RETURN_NONE;
        }
        else {
+               /* New in 2.8x, since not many types support instancing
+                * we may want to use a flag to avoid looping over all classes. - campbell */
+               {
+                       void **instance = RNA_struct_instance(ptr);
+                       if (instance && *instance) {
+                               pyrna = *instance;
+                               Py_INCREF(pyrna);
+                               return (PyObject *)pyrna;
+                       }
+               }
+
                PyTypeObject *tp = (PyTypeObject *)pyrna_struct_Subtype(ptr);
 
                if (tp) {