[Python-checkins] python/dist/src/Objects listobject.c,2.203,2.204 (original) (raw)
rhettinger at users.sourceforge.net rhettinger at users.sourceforge.net
Wed May 5 01:37:55 EDT 2004
- Previous message: [Python-checkins] python/dist/src/Misc NEWS,1.969,1.970
- Next message: [Python-checkins] python/dist/src/Objects listobject.c,2.204,2.205
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Update of /cvsroot/python/python/dist/src/Objects In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18589/Objects
Modified Files: listobject.c Log Message: SF patch #947476: Apply freelist technique to lists
Re-use list object bodies. Saves calls to malloc() and free() for faster list instantiation and deallocation.
Index: listobject.c
RCS file: /cvsroot/python/python/dist/src/Objects/listobject.c,v retrieving revision 2.203 retrieving revision 2.204 diff -C2 -d -r2.203 -r2.204 *** listobject.c 12 Apr 2004 17:21:03 -0000 2.203 --- listobject.c 5 May 2004 05:37:53 -0000 2.204
*** 50,53 **** --- 50,58 ---- }
- /* 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;
- PyObject * PyList_New(int size)
*** 64,70 **** return PyErr_NoMemory(); } ! op = PyObject_GC_New(PyListObject, &PyList_Type); ! if (op == NULL) { ! return NULL; } if (size <= 0) { --- 69,80 ---- return PyErr_NoMemory(); } ! if (num_free_lists) { ! num_free_lists--; ! op = free_lists[num_free_lists]; ! _Py_NewReference((PyObject *)op); ! } else { ! op = PyObject_GC_New(PyListObject, &PyList_Type); ! if (op == NULL) ! return NULL; } if (size <= 0) {
*** 234,238 **** PyMem_FREE(op->ob_item); } ! op->ob_type->tp_free((PyObject *)op); Py_TRASHCAN_SAFE_END(op) } --- 244,251 ---- PyMem_FREE(op->ob_item); } ! if (num_free_lists < MAXFREELISTS && PyList_CheckExact(op)) ! free_lists[num_free_lists++] = op; ! else ! op->ob_type->tp_free((PyObject *)op); Py_TRASHCAN_SAFE_END(op) }
- Previous message: [Python-checkins] python/dist/src/Misc NEWS,1.969,1.970
- Next message: [Python-checkins] python/dist/src/Objects listobject.c,2.204,2.205
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]