summaryrefslogtreecommitdiffstats
path: root/Objects/dictobject.c
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2004-03-08 04:19:01 (GMT)
committerRaymond Hettinger <python@rcn.com>2004-03-08 04:19:01 (GMT)
commitebedb2f773508ec50df1130bdd53b150a9fab84c (patch)
treeb75ca00fd21bd9ffccdce389a4b823d426ad09d3 /Objects/dictobject.c
parent8172ac3d15a78d0a7a716465b5ce6d9f63434a08 (diff)
downloadcpython-ebedb2f773508ec50df1130bdd53b150a9fab84c.zip
cpython-ebedb2f773508ec50df1130bdd53b150a9fab84c.tar.gz
cpython-ebedb2f773508ec50df1130bdd53b150a9fab84c.tar.bz2
Factor out code common to PyDict_Copy() and PyDict_Merge().
Diffstat (limited to 'Objects/dictobject.c')
-rw-r--r--Objects/dictobject.c26
1 files changed, 6 insertions, 20 deletions
diff --git a/Objects/dictobject.c b/Objects/dictobject.c
index b5cbd66..0667bdc 100644
--- a/Objects/dictobject.c
+++ b/Objects/dictobject.c
@@ -1242,33 +1242,19 @@ dict_copy(register dictobject *mp)
PyObject *
PyDict_Copy(PyObject *o)
{
- register dictobject *mp;
- register int i;
- dictobject *copy;
- dictentry *entry;
+ PyObject *copy;
if (o == NULL || !PyDict_Check(o)) {
PyErr_BadInternalCall();
return NULL;
}
- mp = (dictobject *)o;
- copy = (dictobject *)PyDict_New();
+ copy = PyDict_New();
if (copy == NULL)
return NULL;
- if (mp->ma_used > 0) {
- if (dictresize(copy, mp->ma_used*2) != 0)
- return NULL;
- for (i = 0; i <= mp->ma_mask; i++) {
- 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;
+ if (PyDict_Merge(copy, o, 1) == 0)
+ return copy;
+ Py_DECREF(copy);
+ return copy;
}
int