mirror of
https://github.com/python/cpython.git
synced 2025-08-01 07:33:08 +00:00
bpo-46845: Reduce dict size when all keys are Unicode (GH-31564)
This commit is contained in:
parent
21099fc064
commit
9833bb91e4
9 changed files with 884 additions and 491 deletions
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -70,8 +70,8 @@ A values array
|
|||
Tunable Dictionary Parameters
|
||||
-----------------------------
|
||||
|
||||
See comments for PyDict_MINSIZE_SPLIT, PyDict_MINSIZE_COMBINED,
|
||||
USABLE_FRACTION and GROWTH_RATE in dictobject.c
|
||||
See comments for PyDict_MINSIZE, USABLE_FRACTION and GROWTH_RATE in
|
||||
dictobject.c
|
||||
|
||||
Tune-ups should be measured across a broad range of applications and
|
||||
use cases. A change to any parameter will help in some situations and
|
||||
|
|
1211
Objects/dictobject.c
1211
Objects/dictobject.c
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue