diff options
author | Andi Gutmans <andi@php.net> | 2004-07-30 21:00:37 +0000 |
---|---|---|
committer | Andi Gutmans <andi@php.net> | 2004-07-30 21:00:37 +0000 |
commit | d7c839d54f73c6649a13bc5f2178ec5a81ce930f (patch) | |
tree | b72f7dcdafcf7c9e97c05224136ba95a5c960afe /Zend/zend_ptr_stack.h | |
parent | 138ef9a43e9320a412a40908a8733f66aa4858c7 (diff) | |
download | php-git-d7c839d54f73c6649a13bc5f2178ec5a81ce930f.tar.gz |
- More ptr_stack optimizations and cleanups
Diffstat (limited to 'Zend/zend_ptr_stack.h')
-rw-r--r-- | Zend/zend_ptr_stack.h | 54 |
1 files changed, 29 insertions, 25 deletions
diff --git a/Zend/zend_ptr_stack.h b/Zend/zend_ptr_stack.h index d94be35257..d970568436 100644 --- a/Zend/zend_ptr_stack.h +++ b/Zend/zend_ptr_stack.h @@ -39,7 +39,16 @@ ZEND_API void zend_ptr_stack_destroy(zend_ptr_stack *stack); ZEND_API void zend_ptr_stack_apply(zend_ptr_stack *stack, void (*func)(void *)); ZEND_API void zend_ptr_stack_clean(zend_ptr_stack *stack, void (*func)(void *), zend_bool free_elements); ZEND_API int zend_ptr_stack_num_elements(zend_ptr_stack *stack); +END_EXTERN_C() +#define ZEND_PTR_STACK_RESIZE_IF_NEEDED(stack, count) \ + if (stack->top+count > stack->max) { \ + /* we need to allocate more memory */ \ + stack->max *= 2; \ + stack->max += count; \ + stack->elements = (void **) erealloc(stack->elements, (sizeof(void *) * (stack->max))); \ + stack->top_element = stack->elements+stack->top; \ + } /* Not doing this with a macro because of the loop unrolling in the element assignment. Just using a macro for 3 in the body for readability sake. */ @@ -47,12 +56,7 @@ static inline void zend_ptr_stack_3_push(zend_ptr_stack *stack, void *a, void *b { #define ZEND_PTR_STACK_NUM_ARGS 3 - if (stack->top+ZEND_PTR_STACK_NUM_ARGS > stack->max) { /* we need to allocate more memory */ - stack->max *= 2; - stack->max += ZEND_PTR_STACK_NUM_ARGS; - stack->elements = (void **) erealloc(stack->elements, (sizeof(void *) * (stack->max))); - stack->top_element = stack->elements+stack->top; - } + ZEND_PTR_STACK_RESIZE_IF_NEEDED(stack, ZEND_PTR_STACK_NUM_ARGS) stack->top += ZEND_PTR_STACK_NUM_ARGS; *(stack->top_element++) = a; @@ -62,31 +66,31 @@ static inline void zend_ptr_stack_3_push(zend_ptr_stack *stack, void *a, void *b #undef ZEND_PTR_STACK_NUM_ARGS } -/* -ZEND_API void zend_ptr_stack_n_pop(zend_ptr_stack *stack, int count, ...) +static inline void zend_ptr_stack_2_push(zend_ptr_stack *stack, void *a, void *b) { - va_list ptr; - void **elem; - - va_start(ptr, count); - while (count>0) { - elem = va_arg(ptr, void **); - *elem = *(--stack->top_element); - stack->top--; - count--; - } - va_end(ptr); +#define ZEND_PTR_STACK_NUM_ARGS 2 + + ZEND_PTR_STACK_RESIZE_IF_NEEDED(stack, ZEND_PTR_STACK_NUM_ARGS) + + stack->top += ZEND_PTR_STACK_NUM_ARGS; + *(stack->top_element++) = a; + *(stack->top_element++) = b; + +#undef ZEND_PTR_STACK_NUM_ARGS } -*/ -END_EXTERN_C() +static inline void zend_ptr_stack_3_pop(zend_ptr_stack *stack, void **a, void **b, void **c) +{ + *a = *(--stack->top_element); + *b = *(--stack->top_element); + *c = *(--stack->top_element); + stack->top -= 3;; +} static inline void zend_ptr_stack_push(zend_ptr_stack *stack, void *ptr) { - if (stack->top >= stack->max) { /* we need to allocate more memory */ - stack->elements = (void **) erealloc(stack->elements, (sizeof(void *) * (stack->max *= 2 ))); - stack->top_element = stack->elements+stack->top; - } + ZEND_PTR_STACK_RESIZE_IF_NEEDED(stack, 1) + stack->top++; *(stack->top_element++) = ptr; } |