SF #561244 Micro optimizations

Convert loops to memset()s.
This commit is contained in:
Neal Norwitz 2002-06-13 21:11:11 +00:00
parent 606edc1d97
commit 35fc7606f0
3 changed files with 7 additions and 14 deletions

View File

@ -1376,13 +1376,10 @@ sre_getlower(PyObject* self, PyObject* args)
LOCAL(void) LOCAL(void)
state_reset(SRE_STATE* state) state_reset(SRE_STATE* state)
{ {
int i;
state->lastmark = 0; state->lastmark = 0;
/* FIXME: dynamic! */ /* FIXME: dynamic! */
for (i = 0; i < SRE_MARK_SIZE; i++) memset(state->mark, 0, sizeof(*state->mark) * SRE_MARK_SIZE);
state->mark[i] = NULL;
state->lastindex = -1; state->lastindex = -1;

View File

@ -56,7 +56,6 @@ do { \
PyObject * PyObject *
PyList_New(int size) PyList_New(int size)
{ {
int i;
PyListObject *op; PyListObject *op;
size_t nbytes; size_t nbytes;
if (size < 0) { if (size < 0) {
@ -80,10 +79,9 @@ PyList_New(int size)
if (op->ob_item == NULL) { if (op->ob_item == NULL) {
return PyErr_NoMemory(); return PyErr_NoMemory();
} }
memset(op->ob_item, 0, sizeof(*op->ob_item) * size);
} }
op->ob_size = size; op->ob_size = size;
for (i = 0; i < size; i++)
op->ob_item[i] = NULL;
_PyObject_GC_TRACK(op); _PyObject_GC_TRACK(op);
return (PyObject *) op; return (PyObject *) op;
} }
@ -1576,8 +1574,7 @@ list_fill(PyListObject *result, PyObject *v)
PyErr_NoMemory(); PyErr_NoMemory();
goto error; goto error;
} }
for (i = 0; i < n; i++) memset(result->ob_item, 0, sizeof(*result->ob_item) * n);
result->ob_item[i] = NULL;
result->ob_size = n; result->ob_size = n;
/* Run iterator to exhaustion. */ /* Run iterator to exhaustion. */

View File

@ -26,7 +26,6 @@ int tuple_zero_allocs;
PyObject * PyObject *
PyTuple_New(register int size) PyTuple_New(register int size)
{ {
register int i;
register PyTupleObject *op; register PyTupleObject *op;
if (size < 0) { if (size < 0) {
PyErr_BadInternalCall(); PyErr_BadInternalCall();
@ -71,8 +70,7 @@ PyTuple_New(register int size)
if (op == NULL) if (op == NULL)
return NULL; return NULL;
} }
for (i = 0; i < size; i++) memset(op->ob_item, 0, sizeof(*op->ob_item) * size);
op->ob_item[i] = NULL;
#if MAXSAVESIZE > 0 #if MAXSAVESIZE > 0
if (size == 0) { if (size == 0) {
free_tuples[0] = op; free_tuples[0] = op;
@ -697,8 +695,9 @@ _PyTuple_Resize(PyObject **pv, int newsize)
} }
_Py_NewReference((PyObject *) sv); _Py_NewReference((PyObject *) sv);
/* Zero out items added by growing */ /* Zero out items added by growing */
for (i = oldsize; i < newsize; i++) if (newsize > oldsize)
sv->ob_item[i] = NULL; memset(sv->ob_item, 0,
sizeof(*sv->ob_item) * (newsize - oldsize));
*pv = (PyObject *) sv; *pv = (PyObject *) sv;
_PyObject_GC_TRACK(sv); _PyObject_GC_TRACK(sv);
return 0; return 0;