mirror of
https://github.com/python/cpython.git
synced 2025-09-26 10:19:53 +00:00
Cleanup dictobject.c
This commit is contained in:
parent
fdcbab9602
commit
a9f61a5a23
1 changed files with 18 additions and 16 deletions
|
@ -305,9 +305,9 @@ PyDict_Fini(void)
|
||||||
* #define USABLE_FRACTION(n) (((n) >> 1) + ((n) >> 2) - ((n) >> 3))
|
* #define USABLE_FRACTION(n) (((n) >> 1) + ((n) >> 2) - ((n) >> 3))
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* GROWTH_RATE. Growth rate upon hitting maximum load.
|
/* GROWTH_RATE. Growth rate upon hitting maximum load.
|
||||||
* Currently set to used*2 + capacity/2.
|
* Currently set to used*2 + capacity/2.
|
||||||
* This means that dicts double in size when growing without deletions,
|
* This means that dicts double in size when growing without deletions,
|
||||||
* but have more head room when the number of deletions is on a par with the
|
* but have more head room when the number of deletions is on a par with the
|
||||||
* number of insertions.
|
* number of insertions.
|
||||||
* Raising this to used*4 doubles memory consumption depending on the size of
|
* Raising this to used*4 doubles memory consumption depending on the size of
|
||||||
|
@ -2589,23 +2589,25 @@ static PyObject *
|
||||||
dict_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
dict_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||||
{
|
{
|
||||||
PyObject *self;
|
PyObject *self;
|
||||||
|
PyDictObject *d;
|
||||||
|
|
||||||
assert(type != NULL && type->tp_alloc != NULL);
|
assert(type != NULL && type->tp_alloc != NULL);
|
||||||
self = type->tp_alloc(type, 0);
|
self = type->tp_alloc(type, 0);
|
||||||
if (self != NULL) {
|
if (self == NULL)
|
||||||
PyDictObject *d = (PyDictObject *)self;
|
return NULL;
|
||||||
d->ma_keys = new_keys_object(PyDict_MINSIZE_COMBINED);
|
|
||||||
/* XXX - Should we raise a no-memory error? */
|
d = (PyDictObject *)self;
|
||||||
if (d->ma_keys == NULL) {
|
d->ma_keys = new_keys_object(PyDict_MINSIZE_COMBINED);
|
||||||
DK_INCREF(Py_EMPTY_KEYS);
|
/* XXX - Should we raise a no-memory error? */
|
||||||
d->ma_keys = Py_EMPTY_KEYS;
|
if (d->ma_keys == NULL) {
|
||||||
d->ma_values = empty_values;
|
DK_INCREF(Py_EMPTY_KEYS);
|
||||||
}
|
d->ma_keys = Py_EMPTY_KEYS;
|
||||||
d->ma_used = 0;
|
d->ma_values = empty_values;
|
||||||
/* The object has been implicitly tracked by tp_alloc */
|
|
||||||
if (type == &PyDict_Type)
|
|
||||||
_PyObject_GC_UNTRACK(d);
|
|
||||||
}
|
}
|
||||||
|
d->ma_used = 0;
|
||||||
|
/* The object has been implicitly tracked by tp_alloc */
|
||||||
|
if (type == &PyDict_Type)
|
||||||
|
_PyObject_GC_UNTRACK(d);
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue