diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2015-12-22 06:16:18 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2015-12-22 06:16:18 (GMT) |
commit | 0ce7a3a34cec0e625f63d46390a8c1d2e167494f (patch) | |
tree | b4de6a4570fc14109dcc2b2c4f5adc2b3be8d2af /Objects/dictobject.c | |
parent | 5af856404afc1b1e6b9dd4ac86a5771a407cbc6a (diff) | |
download | cpython-0ce7a3a34cec0e625f63d46390a8c1d2e167494f.zip cpython-0ce7a3a34cec0e625f63d46390a8c1d2e167494f.tar.gz cpython-0ce7a3a34cec0e625f63d46390a8c1d2e167494f.tar.bz2 |
Issue #25914: Fixed and simplified OrderedDict.__sizeof__.
Diffstat (limited to 'Objects/dictobject.c')
-rw-r--r-- | Objects/dictobject.c | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/Objects/dictobject.c b/Objects/dictobject.c index 3e6e112..f53cd40 100644 --- a/Objects/dictobject.c +++ b/Objects/dictobject.c @@ -2554,7 +2554,7 @@ dict_tp_clear(PyObject *op) static PyObject *dictiter_new(PyDictObject *, PyTypeObject *); -PyObject * +Py_ssize_t _PyDict_SizeOf(PyDictObject *mp) { Py_ssize_t size, res; @@ -2567,7 +2567,7 @@ _PyDict_SizeOf(PyDictObject *mp) in the type object. */ if (mp->ma_keys->dk_refcnt == 1) res += sizeof(PyDictKeysObject) + (size-1) * sizeof(PyDictKeyEntry); - return PyLong_FromSsize_t(res); + return res; } Py_ssize_t @@ -2576,6 +2576,12 @@ _PyDict_KeysSize(PyDictKeysObject *keys) return sizeof(PyDictKeysObject) + (DK_SIZE(keys)-1) * sizeof(PyDictKeyEntry); } +PyObject * +dict_sizeof(PyDictObject *mp) +{ + return PyLong_FromSsize_t(_PyDict_SizeOf(mp)); +} + PyDoc_STRVAR(getitem__doc__, "x.__getitem__(y) <==> x[y]"); PyDoc_STRVAR(sizeof__doc__, @@ -2623,7 +2629,7 @@ static PyMethodDef mapp_methods[] = { DICT___CONTAINS___METHODDEF {"__getitem__", (PyCFunction)dict_subscript, METH_O | METH_COEXIST, getitem__doc__}, - {"__sizeof__", (PyCFunction)_PyDict_SizeOf, METH_NOARGS, + {"__sizeof__", (PyCFunction)dict_sizeof, METH_NOARGS, sizeof__doc__}, {"get", (PyCFunction)dict_get, METH_VARARGS, get__doc__}, |