diff options
author | Neal Norwitz <nnorwitz@gmail.com> | 2002-06-13 21:11:11 (GMT) |
---|---|---|
committer | Neal Norwitz <nnorwitz@gmail.com> | 2002-06-13 21:11:11 (GMT) |
commit | 35fc7606f076f507bd25acaf464e83c75c3756f4 (patch) | |
tree | 30ac7b6223407e2660a1c7d542f01a1560b407d0 | |
parent | 606edc1d971a0c5e4f5d379ecfa69f42b5b1d691 (diff) | |
download | cpython-35fc7606f076f507bd25acaf464e83c75c3756f4.zip cpython-35fc7606f076f507bd25acaf464e83c75c3756f4.tar.gz cpython-35fc7606f076f507bd25acaf464e83c75c3756f4.tar.bz2 |
SF #561244 Micro optimizations
Convert loops to memset()s.
-rw-r--r-- | Modules/_sre.c | 5 | ||||
-rw-r--r-- | Objects/listobject.c | 7 | ||||
-rw-r--r-- | Objects/tupleobject.c | 9 |
3 files changed, 7 insertions, 14 deletions
diff --git a/Modules/_sre.c b/Modules/_sre.c index b98f6e6..839763d 100644 --- a/Modules/_sre.c +++ b/Modules/_sre.c @@ -1376,13 +1376,10 @@ sre_getlower(PyObject* self, PyObject* args) LOCAL(void) state_reset(SRE_STATE* state) { - int i; - state->lastmark = 0; /* FIXME: dynamic! */ - for (i = 0; i < SRE_MARK_SIZE; i++) - state->mark[i] = NULL; + memset(state->mark, 0, sizeof(*state->mark) * SRE_MARK_SIZE); state->lastindex = -1; diff --git a/Objects/listobject.c b/Objects/listobject.c index f29774e..78cc679 100644 --- a/Objects/listobject.c +++ b/Objects/listobject.c @@ -56,7 +56,6 @@ do { \ PyObject * PyList_New(int size) { - int i; PyListObject *op; size_t nbytes; if (size < 0) { @@ -80,10 +79,9 @@ PyList_New(int size) if (op->ob_item == NULL) { return PyErr_NoMemory(); } + memset(op->ob_item, 0, sizeof(*op->ob_item) * size); } op->ob_size = size; - for (i = 0; i < size; i++) - op->ob_item[i] = NULL; _PyObject_GC_TRACK(op); return (PyObject *) op; } @@ -1576,8 +1574,7 @@ list_fill(PyListObject *result, PyObject *v) PyErr_NoMemory(); goto error; } - for (i = 0; i < n; i++) - result->ob_item[i] = NULL; + memset(result->ob_item, 0, sizeof(*result->ob_item) * n); result->ob_size = n; /* Run iterator to exhaustion. */ diff --git a/Objects/tupleobject.c b/Objects/tupleobject.c index a207102..525e8f6 100644 --- a/Objects/tupleobject.c +++ b/Objects/tupleobject.c @@ -26,7 +26,6 @@ int tuple_zero_allocs; PyObject * PyTuple_New(register int size) { - register int i; register PyTupleObject *op; if (size < 0) { PyErr_BadInternalCall(); @@ -71,8 +70,7 @@ PyTuple_New(register int size) if (op == NULL) return NULL; } - for (i = 0; i < size; i++) - op->ob_item[i] = NULL; + memset(op->ob_item, 0, sizeof(*op->ob_item) * size); #if MAXSAVESIZE > 0 if (size == 0) { free_tuples[0] = op; @@ -697,8 +695,9 @@ _PyTuple_Resize(PyObject **pv, int newsize) } _Py_NewReference((PyObject *) sv); /* Zero out items added by growing */ - for (i = oldsize; i < newsize; i++) - sv->ob_item[i] = NULL; + if (newsize > oldsize) + memset(sv->ob_item, 0, + sizeof(*sv->ob_item) * (newsize - oldsize)); *pv = (PyObject *) sv; _PyObject_GC_TRACK(sv); return 0; |