Commit f163aeaa authored by Serhiy Storchaka's avatar Serhiy Storchaka Committed by GitHub

bpo-38219: Optimize dict creating and updating by a dict. (GH-16268)

parent ad7736fa
Optimized the :class:`dict` constructor and the :meth:`~dict.update` method
for the case when the argument is a dict.
......@@ -2317,17 +2317,22 @@ dict_update_common(PyObject *self, PyObject *args, PyObject *kwds,
result = -1;
}
else if (arg != NULL) {
_Py_IDENTIFIER(keys);
PyObject *func;
if (_PyObject_LookupAttrId(arg, &PyId_keys, &func) < 0) {
result = -1;
}
else if (func != NULL) {
Py_DECREF(func);
if (PyDict_CheckExact(arg)) {
result = PyDict_Merge(self, arg, 1);
}
else {
result = PyDict_MergeFromSeq2(self, arg, 1);
_Py_IDENTIFIER(keys);
PyObject *func;
if (_PyObject_LookupAttrId(arg, &PyId_keys, &func) < 0) {
result = -1;
}
else if (func != NULL) {
Py_DECREF(func);
result = PyDict_Merge(self, arg, 1);
}
else {
result = PyDict_MergeFromSeq2(self, arg, 1);
}
}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment