Kaydet (Commit) 2d40077b authored tarafından Jack Diederich's avatar Jack Diederich

needforspeed: use PyObject_MALLOC instead of system malloc for small

allocations.  Use PyMem_MALLOC for larger (1k+) chunks.  1%-2% speedup.
üst 2b38e40a
...@@ -254,7 +254,7 @@ static void ...@@ -254,7 +254,7 @@ static void
data_stack_dealloc(SRE_STATE* state) data_stack_dealloc(SRE_STATE* state)
{ {
if (state->data_stack) { if (state->data_stack) {
free(state->data_stack); PyMem_FREE(state->data_stack);
state->data_stack = NULL; state->data_stack = NULL;
} }
state->data_stack_size = state->data_stack_base = 0; state->data_stack_size = state->data_stack_base = 0;
...@@ -270,7 +270,7 @@ data_stack_grow(SRE_STATE* state, int size) ...@@ -270,7 +270,7 @@ data_stack_grow(SRE_STATE* state, int size)
void* stack; void* stack;
cursize = minsize+minsize/4+1024; cursize = minsize+minsize/4+1024;
TRACE(("allocate/grow stack %d\n", cursize)); TRACE(("allocate/grow stack %d\n", cursize));
stack = realloc(state->data_stack, cursize); stack = PyMem_REALLOC(state->data_stack, cursize);
if (!stack) { if (!stack) {
data_stack_dealloc(state); data_stack_dealloc(state);
return SRE_ERROR_MEMORY; return SRE_ERROR_MEMORY;
...@@ -1163,7 +1163,7 @@ entrance: ...@@ -1163,7 +1163,7 @@ entrance:
ctx->pattern[1], ctx->pattern[2])); ctx->pattern[1], ctx->pattern[2]));
/* install new repeat context */ /* install new repeat context */
ctx->u.rep = (SRE_REPEAT*) malloc(sizeof(*ctx->u.rep)); ctx->u.rep = (SRE_REPEAT*) PyObject_MALLOC(sizeof(*ctx->u.rep));
ctx->u.rep->count = -1; ctx->u.rep->count = -1;
ctx->u.rep->pattern = ctx->pattern; ctx->u.rep->pattern = ctx->pattern;
ctx->u.rep->prev = state->repeat; ctx->u.rep->prev = state->repeat;
...@@ -1173,7 +1173,7 @@ entrance: ...@@ -1173,7 +1173,7 @@ entrance:
state->ptr = ctx->ptr; state->ptr = ctx->ptr;
DO_JUMP(JUMP_REPEAT, jump_repeat, ctx->pattern+ctx->pattern[0]); DO_JUMP(JUMP_REPEAT, jump_repeat, ctx->pattern+ctx->pattern[0]);
state->repeat = ctx->u.rep->prev; state->repeat = ctx->u.rep->prev;
free(ctx->u.rep); PyObject_FREE(ctx->u.rep);
if (ret) { if (ret) {
RETURN_ON_ERROR(ret); RETURN_ON_ERROR(ret);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment