Issue #13389: Full garbage collection passes now clear the freelists for

list and dict objects.  They already cleared other freelists in the
interpreter.
This commit is contained in:
Antoine Pitrou 2011-11-15 00:00:12 +01:00
parent d8b9ae6e8f
commit 9a812cbc89
8 changed files with 44 additions and 6 deletions

View File

@ -209,3 +209,10 @@ Dictionary Objects
for key, value in seq2:
if override or key not in a:
a[key] = value
.. c:function:: int PyDict_ClearFreeList()
Clear the free list. Return the total number of freed items.
.. versionadded:: 3.3

View File

@ -142,3 +142,10 @@ List Objects
Return a new tuple object containing the contents of *list*; equivalent to
``tuple(list)``.
.. c:function:: int PyList_ClearFreeList()
Clear the free list. Return the total number of freed items.
.. versionadded:: 3.3

View File

@ -129,6 +129,8 @@ PyAPI_FUNC(int) _PyDict_Contains(PyObject *mp, PyObject *key, Py_hash_t hash);
PyAPI_FUNC(PyObject *) _PyDict_NewPresized(Py_ssize_t minused);
PyAPI_FUNC(void) _PyDict_MaybeUntrack(PyObject *mp);
PyAPI_FUNC(int) _PyDict_HasOnlyStringKeys(PyObject *mp);
PyAPI_FUNC(int) PyDict_ClearFreeList(void);
#endif
/* PyDict_Update(mp, other) is equivalent to PyDict_Merge(mp, other, 1). */

View File

@ -62,6 +62,8 @@ PyAPI_FUNC(int) PyList_Reverse(PyObject *);
PyAPI_FUNC(PyObject *) PyList_AsTuple(PyObject *);
#ifndef Py_LIMITED_API
PyAPI_FUNC(PyObject *) _PyList_Extend(PyListObject *, PyObject *);
PyAPI_FUNC(int) PyList_ClearFreeList(void);
#endif
/* Macro, trading safety for speed */

View File

@ -10,6 +10,10 @@ What's New in Python 3.3 Alpha 1?
Core and Builtins
-----------------
- Issue #13389: Full garbage collection passes now clear the freelists for
list and dict objects. They already cleared other freelists in the
interpreter.
- Issue #13327: Remove the need for an explicit None as the second argument
to os.utime, os.lutimes, os.futimes, os.futimens, os.futimesat, in
order to update to the current time. Also added keyword argument

View File

@ -762,6 +762,8 @@ clear_freelists(void)
(void)PyTuple_ClearFreeList();
(void)PyUnicode_ClearFreeList();
(void)PyFloat_ClearFreeList();
(void)PyList_ClearFreeList();
(void)PyDict_ClearFreeList();
}
static double

View File

@ -217,16 +217,23 @@ show_track(void)
static PyDictObject *free_list[PyDict_MAXFREELIST];
static int numfree = 0;
void
PyDict_Fini(void)
int
PyDict_ClearFreeList(void)
{
PyDictObject *op;
int ret = numfree;
while (numfree) {
op = free_list[--numfree];
assert(PyDict_CheckExact(op));
PyObject_GC_Del(op);
}
return ret;
}
void
PyDict_Fini(void)
{
PyDict_ClearFreeList();
}
PyObject *

View File

@ -97,16 +97,23 @@ show_alloc(void)
static PyListObject *free_list[PyList_MAXFREELIST];
static int numfree = 0;
void
PyList_Fini(void)
int
PyList_ClearFreeList(void)
{
PyListObject *op;
int ret = numfree;
while (numfree) {
op = free_list[--numfree];
assert(PyList_CheckExact(op));
PyObject_GC_Del(op);
}
return ret;
}
void
PyList_Fini(void)
{
PyList_ClearFreeList();
}
PyObject *