mirror of
https://github.com/python/cpython.git
synced 2025-12-04 00:30:19 +00:00
Unified naming convention for free lists and their limits. All free lists
in Object/ are named ``free_list``, the counter ``numfree`` and the upper limit is a macro ``PyName_MAXFREELIST`` inside an #ifndef block. The chances should make it easier to adjust Python for platforms with less memory, e.g. mobile phones.
This commit is contained in:
parent
6075a82243
commit
5b970ad483
9 changed files with 99 additions and 84 deletions
|
|
@ -183,9 +183,11 @@ show_counts(void)
|
|||
} while(0)
|
||||
|
||||
/* Dictionary reuse scheme to save calls to malloc, free, and memset */
|
||||
#define MAXFREEDICTS 80
|
||||
static PyDictObject *free_dicts[MAXFREEDICTS];
|
||||
static int num_free_dicts = 0;
|
||||
#ifndef PyDict_MAXFREELIST
|
||||
#define PyDict_MAXFREELIST 80
|
||||
#endif
|
||||
static PyDictObject *free_list[PyDict_MAXFREELIST];
|
||||
static int numfree = 0;
|
||||
|
||||
PyObject *
|
||||
PyDict_New(void)
|
||||
|
|
@ -199,8 +201,8 @@ PyDict_New(void)
|
|||
Py_AtExit(show_counts);
|
||||
#endif
|
||||
}
|
||||
if (num_free_dicts) {
|
||||
mp = free_dicts[--num_free_dicts];
|
||||
if (numfree) {
|
||||
mp = free_list[--numfree];
|
||||
assert (mp != NULL);
|
||||
assert (Py_TYPE(mp) == &PyDict_Type);
|
||||
_Py_NewReference((PyObject *)mp);
|
||||
|
|
@ -868,8 +870,8 @@ dict_dealloc(register PyDictObject *mp)
|
|||
}
|
||||
if (mp->ma_table != mp->ma_smalltable)
|
||||
PyMem_DEL(mp->ma_table);
|
||||
if (num_free_dicts < MAXFREEDICTS && Py_TYPE(mp) == &PyDict_Type)
|
||||
free_dicts[num_free_dicts++] = mp;
|
||||
if (numfree < PyDict_MAXFREELIST && Py_TYPE(mp) == &PyDict_Type)
|
||||
free_list[numfree++] = mp;
|
||||
else
|
||||
Py_TYPE(mp)->tp_free((PyObject *)mp);
|
||||
Py_TRASHCAN_SAFE_END(mp)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue