bpo-46845: Reduce dict size when all keys are Unicode (GH-31564)
This commit is contained in:
@@ -934,26 +934,11 @@ PyObject *
|
||||
_PyStack_AsDict(PyObject *const *values, PyObject *kwnames)
|
||||
{
|
||||
Py_ssize_t nkwargs;
|
||||
PyObject *kwdict;
|
||||
Py_ssize_t i;
|
||||
|
||||
assert(kwnames != NULL);
|
||||
nkwargs = PyTuple_GET_SIZE(kwnames);
|
||||
kwdict = _PyDict_NewPresized(nkwargs);
|
||||
if (kwdict == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
for (i = 0; i < nkwargs; i++) {
|
||||
PyObject *key = PyTuple_GET_ITEM(kwnames, i);
|
||||
PyObject *value = *values++;
|
||||
/* If key already exists, replace it with the new value */
|
||||
if (PyDict_SetItem(kwdict, key, value)) {
|
||||
Py_DECREF(kwdict);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
return kwdict;
|
||||
return _PyDict_FromItems(&PyTuple_GET_ITEM(kwnames, 0), 1,
|
||||
values, 1, nkwargs);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user