Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2017-07-20 17:45:35 +0300
committerCampbell Barton <ideasman42@gmail.com>2017-07-20 17:50:18 +0300
commit6b0d4302beb5e79a6569b4afe17d05150cdf42d0 (patch)
tree3cd383c871d09eac42c894ce893e935aea516e4a /source/blender
parent57ee488404a85287cecf8dd09349b961e7f068ee (diff)
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).
Diffstat (limited to 'source/blender')
-rw-r--r--source/blender/python/intern/bpy_rna.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/source/blender/python/intern/bpy_rna.c b/source/blender/python/intern/bpy_rna.c
index 51e179fb317..ca1e74ce28e 100644
--- a/source/blender/python/intern/bpy_rna.c
+++ b/source/blender/python/intern/bpy_rna.c
@@ -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) {