Skip to content

Commit

Permalink
Avoid a costly Python dict creation in a function call when we'd only…
Browse files Browse the repository at this point in the history
… pass the default argument.
  • Loading branch information
scoder committed Oct 24, 2023
1 parent f0d2a1a commit edaea23
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions Cython/Utility/TypeConversion.c
Original file line number Diff line number Diff line change
Expand Up @@ -865,9 +865,12 @@ static CYTHON_INLINE PyObject* {{TO_PY_FUNCTION}}({{TYPE}} value) {
if (!order_str) goto limited_bad;
arg_tuple = PyTuple_Pack(2, py_bytes, order_str);
if (!arg_tuple) goto limited_bad;
kwds = PyDict_New();
if (!kwds) goto limited_bad;
if (PyDict_SetItemString(kwds, "signed", __Pyx_NewRef(!is_unsigned ? Py_True : Py_False))) goto limited_bad;
if (!is_unsigned) {
// default is signed=False
kwds = PyDict_New();
if (!kwds) goto limited_bad;
if (PyDict_SetItemString(kwds, "signed", __Pyx_NewRef(Py_True))) goto limited_bad;
}
result = PyObject_Call(from_bytes, arg_tuple, kwds);

limited_bad:
Expand Down

0 comments on commit edaea23

Please sign in to comment.