mirror of
https://github.com/python/cpython.git
synced 2024-11-28 20:33:54 +08:00
bpo-38219: Optimize dict creating and updating by a dict. (GH-16268)
This commit is contained in:
parent
ad7736faf5
commit
f163aeaa8c
@ -0,0 +1,2 @@
|
||||
Optimized the :class:`dict` constructor and the :meth:`~dict.update` method
|
||||
for the case when the argument is a dict.
|
@ -2317,6 +2317,10 @@ dict_update_common(PyObject *self, PyObject *args, PyObject *kwds,
|
||||
result = -1;
|
||||
}
|
||||
else if (arg != NULL) {
|
||||
if (PyDict_CheckExact(arg)) {
|
||||
result = PyDict_Merge(self, arg, 1);
|
||||
}
|
||||
else {
|
||||
_Py_IDENTIFIER(keys);
|
||||
PyObject *func;
|
||||
if (_PyObject_LookupAttrId(arg, &PyId_keys, &func) < 0) {
|
||||
@ -2330,6 +2334,7 @@ dict_update_common(PyObject *self, PyObject *args, PyObject *kwds,
|
||||
result = PyDict_MergeFromSeq2(self, arg, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (result == 0 && kwds != NULL) {
|
||||
if (PyArg_ValidateKeywordArguments(kwds))
|
||||
|
Loading…
Reference in New Issue
Block a user