PyAPI: minor optimization for dictionary creation
Pass size when its known.
This commit is contained in:
@@ -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);
|
||||
|
@@ -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) {
|
||||
|
@@ -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);
|
||||
|
@@ -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;
|
||||
|
||||
|
@@ -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);
|
||||
|
@@ -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);
|
||||
|
Reference in New Issue
Block a user