forked from github/server
opstack was the #1 malloced datastructure.
This commit is contained in:
parent
85e2dd76d9
commit
3d5c41a273
|
@ -26,32 +26,36 @@
|
||||||
**/
|
**/
|
||||||
|
|
||||||
typedef struct opstack {
|
typedef struct opstack {
|
||||||
struct opstack * next;
|
variant * begin;
|
||||||
variant data;
|
variant * top;
|
||||||
|
int size;
|
||||||
} opstack;
|
} opstack;
|
||||||
|
|
||||||
variant
|
variant
|
||||||
opstack_pop(opstack ** stack)
|
opstack_pop(opstack ** stackp)
|
||||||
{
|
{
|
||||||
opstack * os;
|
opstack * stack = *stackp;
|
||||||
variant data;
|
|
||||||
|
|
||||||
assert(stack);
|
assert(stack);
|
||||||
os = *stack;
|
assert(stack->top>stack->begin);
|
||||||
assert(os);
|
return *(--stack->top);
|
||||||
data = os->data;
|
|
||||||
*stack = os->next;
|
|
||||||
free(os);
|
|
||||||
return data;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
opstack_push(opstack ** stack, variant data)
|
opstack_push(opstack ** stackp, variant data)
|
||||||
{
|
{
|
||||||
opstack * os = (opstack*)malloc(sizeof(opstack));
|
opstack * stack = *stackp;
|
||||||
os->next = *stack;
|
if (stack==NULL) {
|
||||||
os->data = data;
|
stack = (opstack*)malloc(sizeof(opstack));
|
||||||
*stack = os;
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue