From f3b71348b0f42d9d3adc1b6d19da8b3053c17d43 Mon Sep 17 00:00:00 2001 From: Stefan Behnel <stefan_ml@behnel.de> Date: Fri, 15 Sep 2017 07:05:39 +0200 Subject: [PATCH] Avoid calling _PyDict_NewPresized() for len(dict) <=8, which is the minimum dict size in CPython. --- Cython/Utility/Coroutine.c | 2 +- Cython/Utility/ModuleSetupCode.c | 2 +- Cython/Utility/Printing.c | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Cython/Utility/Coroutine.c b/Cython/Utility/Coroutine.c index 43ed8bb7f..5458de474 100644 --- a/Cython/Utility/Coroutine.c +++ b/Cython/Utility/Coroutine.c @@ -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 = __Pyx_PyDict_NewPresized(4); if (unlikely(!globals)) goto ignore; + globals = PyDict_New(); if (unlikely(!globals)) goto ignore; result = PyDict_SetItemString(globals, "_cython_coroutine_type", #ifdef __Pyx_Coroutine_USED (PyObject*)__pyx_CoroutineType); diff --git a/Cython/Utility/ModuleSetupCode.c b/Cython/Utility/ModuleSetupCode.c index 0b892d72a..83ce4d18c 100644 --- a/Cython/Utility/ModuleSetupCode.c +++ b/Cython/Utility/ModuleSetupCode.c @@ -256,7 +256,7 @@ #endif #if CYTHON_COMPILING_IN_CPYTHON || defined(_PyDict_NewPresized) -#define __Pyx_PyDict_NewPresized(n) _PyDict_NewPresized(n) +#define __Pyx_PyDict_NewPresized(n) ((n <= 8) ? PyDict_New() : _PyDict_NewPresized(n)) #else #define __Pyx_PyDict_NewPresized(n) PyDict_New() #endif diff --git a/Cython/Utility/Printing.c b/Cython/Utility/Printing.c index 98bc5acac..71aa7eafe 100644 --- a/Cython/Utility/Printing.c +++ b/Cython/Utility/Printing.c @@ -83,7 +83,7 @@ static int __Pyx_Print(PyObject* stream, PyObject *arg_tuple, int newline) { return -1; } if (stream) { - kwargs = __Pyx_PyDict_NewPresized(2); + kwargs = PyDict_New(); 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 = __Pyx_PyDict_NewPresized(1); + $print_function_kwargs = PyDict_New(); if (unlikely(!$print_function_kwargs)) return -1; end_string = PyUnicode_FromStringAndSize(" ", 1); -- 2.30.9