From 3d5c41a27300610861194cf88835449cf87db250 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 12 Jun 2005 02:18:28 +0000 Subject: [PATCH] opstack was the #1 malloced datastructure. --- src/common/util/translation.c | 38 +++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/src/common/util/translation.c b/src/common/util/translation.c index 324d59d4d..1de83f8e3 100644 --- a/src/common/util/translation.c +++ b/src/common/util/translation.c @@ -26,32 +26,36 @@ **/ typedef struct opstack { - struct opstack * next; - variant data; + variant * begin; + variant * top; + int size; } opstack; variant -opstack_pop(opstack ** stack) +opstack_pop(opstack ** stackp) { - opstack * os; - variant data; - + opstack * stack = *stackp; assert(stack); - os = *stack; - assert(os); - data = os->data; - *stack = os->next; - free(os); - return data; + assert(stack->top>stack->begin); + return *(--stack->top); } void -opstack_push(opstack ** stack, variant data) +opstack_push(opstack ** stackp, variant data) { - opstack * os = (opstack*)malloc(sizeof(opstack)); - os->next = *stack; - os->data = data; - *stack = os; + opstack * stack = *stackp; + if (stack==NULL) { + stack = (opstack*)malloc(sizeof(opstack)); + stack->size = 4; + stack->begin = malloc(sizeof(variant) * stack->size); + stack->top = stack->begin; + *stackp = stack; + } + if (stack->top - stack->begin == stack->size) { + stack->size += stack->size; + stack->begin = realloc(stack->begin, sizeof(variant) * stack->size); + } + *stack->top++ = data; } /**