diff options
author | Guido van Rossum <guido@python.org> | 1998-06-26 15:53:50 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1998-06-26 15:53:50 (GMT) |
commit | 1bb26872f565fa886bc20f94bfdbb1771032fa6a (patch) | |
tree | acf01a92cba644144205fc06080af662d248aefb /Objects/tupleobject.c | |
parent | fb721cf03e0d1de54e12f00eb234d0f6ee09a88d (diff) | |
download | cpython-1bb26872f565fa886bc20f94bfdbb1771032fa6a.zip cpython-1bb26872f565fa886bc20f94bfdbb1771032fa6a.tar.gz cpython-1bb26872f565fa886bc20f94bfdbb1771032fa6a.tar.bz2 |
Slight rearrangement of some code to make it faster, by Vladimir
Marangozov.
Diffstat (limited to 'Objects/tupleobject.c')
-rw-r--r-- | Objects/tupleobject.c | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/Objects/tupleobject.c b/Objects/tupleobject.c index d6fb6b4..9bc1fe7 100644 --- a/Objects/tupleobject.c +++ b/Objects/tupleobject.c @@ -82,9 +82,10 @@ PyTuple_New(size) sizeof(PyTupleObject) + size * sizeof(PyObject *)); if (op == NULL) return PyErr_NoMemory(); + + op->ob_type = &PyTuple_Type; + op->ob_size = size; } - op->ob_type = &PyTuple_Type; - op->ob_size = size; for (i = 0; i < size; i++) op->ob_item[i] = NULL; _Py_NewReference(op); @@ -158,15 +159,20 @@ tupledealloc(op) register PyTupleObject *op; { register int i; - for (i = 0; i < op->ob_size; i++) - Py_XDECREF(op->ob_item[i]); + + if (op->ob_size > 0) { + i = op->ob_size; + while (--i >= 0) + Py_XDECREF(op->ob_item[i]); #if MAXSAVESIZE > 0 - if (0 < op->ob_size && op->ob_size < MAXSAVESIZE) { - op->ob_item[0] = (PyObject *) free_tuples[op->ob_size]; - free_tuples[op->ob_size] = op; - } else + if (op->ob_size < MAXSAVESIZE) { + op->ob_item[0] = (PyObject *) free_tuples[op->ob_size]; + free_tuples[op->ob_size] = op; + return; + } #endif - free((ANY *)op); + } + free((ANY *)op); } static int |