Commit c132ad9c authored by Stefan Behnel's avatar Stefan Behnel

Avoid dict resizing while creating fixed-size dicts.

parent 3fdd71a9
......@@ -8471,8 +8471,9 @@ class DictNode(ExprNode):
if is_dict:
self.release_errors()
code.putln(
"%s = PyDict_New(); %s" % (
"%s = __Pyx_PyDict_NewPresized(%d); %s" % (
self.result(),
len(self.key_value_pairs),
code.error_goto_if_null(self.result(), self.pos)))
code.put_gotref(self.py_result())
......
......@@ -3167,7 +3167,8 @@ class ToPyStructUtilityCode(object):
code.putln("%s {" % self.header)
code.putln("PyObject* res;")
code.putln("PyObject* member;")
code.putln("res = PyDict_New(); if (unlikely(!res)) return NULL;")
code.putln("res = __Pyx_PyDict_NewPresized(%d); if (unlikely(!res)) return NULL;" %
len(self.type.scope.var_entries))
for member in self.type.scope.var_entries:
nameconst_cname = code.get_py_string_const(member.name, identifier=True)
code.putln("%s; if (unlikely(!member)) goto bad;" % (
......
......@@ -1742,7 +1742,7 @@ static PyObject* __Pyx_Coroutine_patch_module(PyObject* module, const char* py_c
#if defined(__Pyx_Generator_USED) || defined(__Pyx_Coroutine_USED)
int result;
PyObject *globals, *result_obj;
globals = PyDict_New(); if (unlikely(!globals)) goto ignore;
globals = __Pyx_PyDict_NewPresized(4); if (unlikely(!globals)) goto ignore;
result = PyDict_SetItemString(globals, "_cython_coroutine_type",
#ifdef __Pyx_Coroutine_USED
(PyObject*)__pyx_CoroutineType);
......
......@@ -255,6 +255,12 @@
#define __Pyx_PyThreadState_Current _PyThreadState_Current
#endif
#if CYTHON_COMPILING_IN_CPYTHON || defined(_PyDict_NewPresized)
#define __Pyx_PyDict_NewPresized(n) _PyDict_NewPresized(n)
#else
#define __Pyx_PyDict_NewPresized(n) PyDict_New()
#endif
#if PY_MAJOR_VERSION >= 3 || CYTHON_FUTURE_DIVISION
#define __Pyx_PyNumber_Divide(x,y) PyNumber_TrueDivide(x,y)
#define __Pyx_PyNumber_InPlaceDivide(x,y) PyNumber_InPlaceTrueDivide(x,y)
......
......@@ -83,7 +83,7 @@ static int __Pyx_Print(PyObject* stream, PyObject *arg_tuple, int newline) {
return -1;
}
if (stream) {
kwargs = PyDict_New();
kwargs = __Pyx_PyDict_NewPresized(2);
if (unlikely(!kwargs))
return -1;
if (unlikely(PyDict_SetItem(kwargs, PYIDENT("file"), stream) < 0))
......@@ -100,7 +100,7 @@ static int __Pyx_Print(PyObject* stream, PyObject *arg_tuple, int newline) {
}
} else if (!newline) {
if (unlikely(!$print_function_kwargs)) {
$print_function_kwargs = PyDict_New();
$print_function_kwargs = __Pyx_PyDict_NewPresized(1);
if (unlikely(!$print_function_kwargs))
return -1;
end_string = PyUnicode_FromStringAndSize(" ", 1);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment