diff options
author | Christian Heimes <christian@cheimes.de> | 2008-02-06 13:33:44 (GMT) |
---|---|---|
committer | Christian Heimes <christian@cheimes.de> | 2008-02-06 13:33:44 (GMT) |
commit | 5b970ad483332dc6c5f3e84a238317d45f844421 (patch) | |
tree | 753dc573beb62ee375d27ebdb8ed58a24683dda2 /Objects/listobject.c | |
parent | 6075a82243c7646dcdd45b424cf3e5c676f31ccf (diff) | |
download | cpython-5b970ad483332dc6c5f3e84a238317d45f844421.zip cpython-5b970ad483332dc6c5f3e84a238317d45f844421.tar.gz cpython-5b970ad483332dc6c5f3e84a238317d45f844421.tar.bz2 |
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.
Diffstat (limited to 'Objects/listobject.c')
-rw-r--r-- | Objects/listobject.c | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/Objects/listobject.c b/Objects/listobject.c index 78e8da4..9e893662 100644 --- a/Objects/listobject.c +++ b/Objects/listobject.c @@ -64,18 +64,20 @@ list_resize(PyListObject *self, Py_ssize_t newsize) } /* Empty list reuse scheme to save calls to malloc and free */ -#define MAXFREELISTS 80 -static PyListObject *free_lists[MAXFREELISTS]; -static int num_free_lists = 0; +#ifndef PyList_MAXFREELIST +#define PyList_MAXFREELIST 80 +#endif +static PyListObject *free_list[PyList_MAXFREELIST]; +static int numfree = 0; void PyList_Fini(void) { PyListObject *op; - while (num_free_lists) { - num_free_lists--; - op = free_lists[num_free_lists]; + while (numfree) { + numfree--; + op = free_list[numfree]; assert(PyList_CheckExact(op)); PyObject_GC_Del(op); } @@ -95,9 +97,9 @@ PyList_New(Py_ssize_t size) /* Check for overflow */ if (nbytes / sizeof(PyObject *) != (size_t)size) return PyErr_NoMemory(); - if (num_free_lists) { - num_free_lists--; - op = free_lists[num_free_lists]; + if (numfree) { + numfree--; + op = free_list[numfree]; _Py_NewReference((PyObject *)op); } else { op = PyObject_GC_New(PyListObject, &PyList_Type); @@ -265,8 +267,8 @@ list_dealloc(PyListObject *op) } PyMem_FREE(op->ob_item); } - if (num_free_lists < MAXFREELISTS && PyList_CheckExact(op)) - free_lists[num_free_lists++] = op; + if (numfree < PyList_MAXFREELIST && PyList_CheckExact(op)) + free_list[numfree++] = op; else Py_TYPE(op)->tp_free((PyObject *)op); Py_TRASHCAN_SAFE_END(op) |