diff options
author | Raymond Hettinger <python@rcn.com> | 2004-03-08 07:25:05 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2004-03-08 07:25:05 (GMT) |
commit | b7d05db0beacb9f24300d5fa26b14c3f73d6c622 (patch) | |
tree | 7e2c7f591d047fdd057b25dcff149f6e78f38e60 /Objects/tupleobject.c | |
parent | f0e3569a28bc25cc3a6b267614b9724d8fe01a0e (diff) | |
download | cpython-b7d05db0beacb9f24300d5fa26b14c3f73d6c622.zip cpython-b7d05db0beacb9f24300d5fa26b14c3f73d6c622.tar.gz cpython-b7d05db0beacb9f24300d5fa26b14c3f73d6c622.tar.bz2 |
Optimize tuple_slice() and make further improvements to list_slice()
and list.extend(). Factoring the inner loops to remove the constant
structure references and fixed offsets gives speedups ranging from
20% to 30%.
Diffstat (limited to 'Objects/tupleobject.c')
-rw-r--r-- | Objects/tupleobject.c | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/Objects/tupleobject.c b/Objects/tupleobject.c index ef5cb85..eaf3c88 100644 --- a/Objects/tupleobject.c +++ b/Objects/tupleobject.c @@ -306,7 +306,9 @@ static PyObject * tupleslice(register PyTupleObject *a, register int ilow, register int ihigh) { register PyTupleObject *np; + PyObject **src, **dest; register int i; + int len; if (ilow < 0) ilow = 0; if (ihigh > a->ob_size) @@ -317,13 +319,16 @@ tupleslice(register PyTupleObject *a, register int ilow, register int ihigh) Py_INCREF(a); return (PyObject *)a; } - np = (PyTupleObject *)PyTuple_New(ihigh - ilow); + len = ihigh - ilow; + np = (PyTupleObject *)PyTuple_New(len); if (np == NULL) return NULL; - for (i = ilow; i < ihigh; i++) { - PyObject *v = a->ob_item[i]; + src = a->ob_item + ilow; + dest = np->ob_item; + for (i = 0; i < len; i++) { + PyObject *v = src[i]; Py_INCREF(v); - np->ob_item[i - ilow] = v; + dest[i] = v; } return (PyObject *)np; } |