Commit: a96c9def6f57269f6ff10a189cd55ff43dc3a15f
Author: Campbell Barton
Date:   Sun Jul 31 17:22:04 2016 +1000
Branches: master
https://developer.blender.org/rBa96c9def6f57269f6ff10a189cd55ff43dc3a15f

PyAPI: minor optimization for dictionary creation

Pass size when its known.

===================================================================

M       source/blender/python/bmesh/bmesh_py_ops_call.c
M       source/blender/python/generic/idprop_py_api.c
M       source/blender/python/intern/bpy_app_translations.c
M       source/blender/python/intern/bpy_driver.c
M       source/blender/python/intern/bpy_library_load.c
M       source/blender/python/intern/bpy_rna_id_collection.c

===================================================================

diff --git a/source/blender/python/bmesh/bmesh_py_ops_call.c 
b/source/blender/python/bmesh/bmesh_py_ops_call.c
index 551a66d..8f28791 100644
--- a/source/blender/python/bmesh/bmesh_py_ops_call.c
+++ b/source/blender/python/bmesh/bmesh_py_ops_call.c
@@ -581,7 +581,7 @@ static PyObject *bpy_slot_to_py(BMesh *bm, BMOpSlot *slot)
                        switch (slot->slot_subtype.map) {
                                case BMO_OP_SLOT_SUBTYPE_MAP_ELEM:
                                {
-                                       item = PyDict_New();
+                                       item = _PyDict_NewPresized(slot_hash ? 
BLI_ghash_size(slot_hash) : 0);
                                        if (slot_hash) {
                                                GHASH_ITER (hash_iter, 
slot_hash) {
                                                        BMHeader *ele_key = 
BLI_ghashIterator_getKey(&hash_iter);
@@ -599,7 +599,7 @@ static PyObject *bpy_slot_to_py(BMesh *bm, BMOpSlot *slot)
                                }
                                case BMO_OP_SLOT_SUBTYPE_MAP_FLT:
                                {
-                                       item = PyDict_New();
+                                       item = _PyDict_NewPresized(slot_hash ? 
BLI_ghash_size(slot_hash) : 0);
                                        if (slot_hash) {
                                                GHASH_ITER (hash_iter, 
slot_hash) {
                                                        BMHeader *ele_key = 
BLI_ghashIterator_getKey(&hash_iter);
@@ -617,7 +617,7 @@ static PyObject *bpy_slot_to_py(BMesh *bm, BMOpSlot *slot)
                                }
                                case BMO_OP_SLOT_SUBTYPE_MAP_INT:
                                {
-                                       item = PyDict_New();
+                                       item = _PyDict_NewPresized(slot_hash ? 
BLI_ghash_size(slot_hash) : 0);
                                        if (slot_hash) {
                                                GHASH_ITER (hash_iter, 
slot_hash) {
                                                        BMHeader *ele_key = 
BLI_ghashIterator_getKey(&hash_iter);
@@ -635,7 +635,7 @@ static PyObject *bpy_slot_to_py(BMesh *bm, BMOpSlot *slot)
                                }
                                case BMO_OP_SLOT_SUBTYPE_MAP_BOOL:
                                {
-                                       item = PyDict_New();
+                                       item = _PyDict_NewPresized(slot_hash ? 
BLI_ghash_size(slot_hash) : 0);
                                        if (slot_hash) {
                                                GHASH_ITER (hash_iter, 
slot_hash) {
                                                        BMHeader *ele_key = 
BLI_ghashIterator_getKey(&hash_iter);
diff --git a/source/blender/python/generic/idprop_py_api.c 
b/source/blender/python/generic/idprop_py_api.c
index 2f8afdf..2e15b7b 100644
--- a/source/blender/python/generic/idprop_py_api.c
+++ b/source/blender/python/generic/idprop_py_api.c
@@ -688,7 +688,7 @@ static PyObject *BPy_IDGroup_MapDataToPy(IDProperty *prop)
                }
                case IDP_GROUP:
                {
-                       PyObject *dict = PyDict_New();
+                       PyObject *dict = _PyDict_NewPresized(prop->len);
                        IDProperty *loop;
 
                        for (loop = prop->data.group.first; loop; loop = 
loop->next) {
diff --git a/source/blender/python/intern/bpy_app_translations.c 
b/source/blender/python/intern/bpy_app_translations.c
index b90deaf..6ba858f 100644
--- a/source/blender/python/intern/bpy_app_translations.c
+++ b/source/blender/python/intern/bpy_app_translations.c
@@ -675,7 +675,7 @@ static PyObject *app_translations_new(PyTypeObject *type, 
PyObject *UNUSED(args)
 
                        _translations->contexts = 
app_translations_contexts_make();
 
-                       py_ctxts = PyDict_New();
+                       py_ctxts = _PyDict_NewPresized(ARRAY_SIZE(_contexts));
                        for (ctxt = _contexts; ctxt->c_id; ctxt++) {
                                PyObject *val = 
PyUnicode_FromString(ctxt->py_id);
                                PyDict_SetItemString(py_ctxts, ctxt->c_id, val);
diff --git a/source/blender/python/intern/bpy_driver.c 
b/source/blender/python/intern/bpy_driver.c
index a03c50d..c8ce7b2 100644
--- a/source/blender/python/intern/bpy_driver.c
+++ b/source/blender/python/intern/bpy_driver.c
@@ -293,7 +293,7 @@ float BPY_driver_exec(struct PathResolvedRNA *anim_rna, 
ChannelDriver *driver, c
        }
 
        /* add target values to a dict that will be used as '__locals__' dict */
-       driver_vars = PyDict_New();
+       driver_vars = _PyDict_NewPresized(PyTuple_GET_SIZE(expr_vars));
        for (dvar = driver->variables.first, i = 0; dvar; dvar = dvar->next) {
                PyObject *driver_arg = NULL;
 
diff --git a/source/blender/python/intern/bpy_library_load.c 
b/source/blender/python/intern/bpy_library_load.c
index 37a7e0e..ec69abb 100644
--- a/source/blender/python/intern/bpy_library_load.c
+++ b/source/blender/python/intern/bpy_library_load.c
@@ -210,7 +210,7 @@ static PyObject *bpy_lib_load(PyObject *UNUSED(self), 
PyObject *args, PyObject *
        ret->flag = ((is_link ? FILE_LINK : 0) |
                     (is_rel ? FILE_RELPATH : 0));
 
-       ret->dict = PyDict_New();
+       ret->dict = _PyDict_NewPresized(MAX_LIBARRAY);
 
        return (PyObject *)ret;
 }
@@ -240,7 +240,7 @@ static PyObject *bpy_lib_enter(BPy_Library *self, PyObject 
*UNUSED(args))
 {
        PyObject *ret;
        BPy_Library *self_from;
-       PyObject *from_dict = PyDict_New();
+       PyObject *from_dict = _PyDict_NewPresized(MAX_LIBARRAY);
        ReportList reports;
 
        BKE_reports_init(&reports, RPT_STORE);
diff --git a/source/blender/python/intern/bpy_rna_id_collection.c 
b/source/blender/python/intern/bpy_rna_id_collection.c
index 104e3e4..31189ba 100644
--- a/source/blender/python/intern/bpy_rna_id_collection.c
+++ b/source/blender/python/intern/bpy_rna_id_collection.c
@@ -198,7 +198,7 @@ static PyObject *bpy_user_map(PyObject *UNUSED(self), 
PyObject *args, PyObject *
                PyObject **subset_array = PySequence_Fast_ITEMS(subset_fast);
                Py_ssize_t subset_len = PySequence_Fast_GET_SIZE(subset_fast);
 
-               data_cb.user_map = PyDict_New();
+               data_cb.user_map = _PyDict_NewPresized(subset_len);
                data_cb.is_subset = true;
                for (; subset_len; subset_array++, subset_len--) {
                        PyObject *set = PySet_New(NULL);

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to