mirror of
https://github.com/python/cpython.git
synced 2025-09-26 10:19:53 +00:00
Factor out code common to PyDict_Copy() and PyDict_Merge().
This commit is contained in:
parent
8172ac3d15
commit
ebedb2f773
1 changed files with 6 additions and 20 deletions
|
@ -1242,33 +1242,19 @@ dict_copy(register dictobject *mp)
|
||||||
PyObject *
|
PyObject *
|
||||||
PyDict_Copy(PyObject *o)
|
PyDict_Copy(PyObject *o)
|
||||||
{
|
{
|
||||||
register dictobject *mp;
|
PyObject *copy;
|
||||||
register int i;
|
|
||||||
dictobject *copy;
|
|
||||||
dictentry *entry;
|
|
||||||
|
|
||||||
if (o == NULL || !PyDict_Check(o)) {
|
if (o == NULL || !PyDict_Check(o)) {
|
||||||
PyErr_BadInternalCall();
|
PyErr_BadInternalCall();
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
mp = (dictobject *)o;
|
copy = PyDict_New();
|
||||||
copy = (dictobject *)PyDict_New();
|
|
||||||
if (copy == NULL)
|
if (copy == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
if (mp->ma_used > 0) {
|
if (PyDict_Merge(copy, o, 1) == 0)
|
||||||
if (dictresize(copy, mp->ma_used*2) != 0)
|
return copy;
|
||||||
return NULL;
|
Py_DECREF(copy);
|
||||||
for (i = 0; i <= mp->ma_mask; i++) {
|
return copy;
|
||||||
entry = &mp->ma_table[i];
|
|
||||||
if (entry->me_value != NULL) {
|
|
||||||
Py_INCREF(entry->me_key);
|
|
||||||
Py_INCREF(entry->me_value);
|
|
||||||
insertdict(copy, entry->me_key, entry->me_hash,
|
|
||||||
entry->me_value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return (PyObject *)copy;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue