]> granicus.if.org Git - php/commitdiff
- More ptr_stack optimizations and cleanups
authorAndi Gutmans <andi@php.net>
Fri, 30 Jul 2004 21:00:37 +0000 (21:00 +0000)
committerAndi Gutmans <andi@php.net>
Fri, 30 Jul 2004 21:00:37 +0000 (21:00 +0000)
Zend/zend_execute.c
Zend/zend_execute_API.c
Zend/zend_ptr_stack.c
Zend/zend_ptr_stack.h

index 9b78925491242a9d6c4f6dd6be8ed461686c0113..686c71eb4a116a63188eefa48a0f27c8be1a9bb1 100644 (file)
@@ -2646,7 +2646,7 @@ int zend_do_fcall_common_helper(ZEND_OPCODE_HANDLER_ARGS)
                NEXT_OPCODE(); /* Never reached */
        }
 
-       zend_ptr_stack_n_push(&EG(argument_stack), 2, (void *) opline->extended_value, NULL);
+       zend_ptr_stack_2_push(&EG(argument_stack), (void *) opline->extended_value, NULL);
 
        EX_T(opline->result.u.var).var.ptr_ptr = &EX_T(opline->result.u.var).var.ptr;
 
@@ -2790,7 +2790,7 @@ int zend_do_fcall_common_helper(ZEND_OPCODE_HANDLER_ARGS)
                EG(This) = current_this;
                EG(scope) = current_scope;
        }
-       zend_ptr_stack_n_pop(&EG(arg_types_stack), 3, &EX(calling_scope), &EX(object), &EX(fbc));
+       zend_ptr_stack_3_pop(&EG(arg_types_stack), &EX(calling_scope), &EX(object), &EX(fbc));
        
        EX(function_state).function = (zend_function *) op_array;
        EG(function_state_ptr) = &EX(function_state);
index 11786e945065e9712f00a66ec579921d28ee45b2..ff540a0965e1eac2bf2970c33961e9ee7792ff94 100644 (file)
@@ -781,7 +781,7 @@ int zend_call_function(zend_fcall_info *fci, zend_fcall_info_cache *fci_cache TS
                fci->param_count = 2;
        }
 
-       zend_ptr_stack_n_push(&EG(argument_stack), 2, (void *) (long) fci->param_count, NULL);
+       zend_ptr_stack_2_push(&EG(argument_stack), (void *) (long) fci->param_count, NULL);
 
        original_function_state_ptr = EG(function_state_ptr);
        EG(function_state_ptr) = &EX(function_state);
index f1e554e10da07118702a95625d84caac0593a213..e15979d9fdeeffaf2f89c95a0e72b19cc4f2219e 100644 (file)
@@ -38,12 +38,8 @@ ZEND_API void zend_ptr_stack_n_push(zend_ptr_stack *stack, int count, ...)
        va_list ptr;
        void *elem;
        
-       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;
-       }
+       ZEND_PTR_STACK_RESIZE_IF_NEEDED(stack, count)
+
        va_start(ptr, count);
        while (count>0) {
                elem = va_arg(ptr, void *);
index d94be352575cbc26a035fda8173977196af96920..d9705684363bde0cc4cbd8547a3ef7d2993e0bee 100644 (file)
@@ -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;
 }