PyAPI: use instancing when supported

This means when a new data-type is returned it will use the same
instance as the previously created one (if it exists).
This commit is contained in:
2017-07-21 00:45:35 +10:00
parent 57ee488404
commit 6b0d4302be

View 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) {