]> granicus.if.org Git - php/commitdiff
- Add ptr_stack_n_{push,pop} in order to speed up function calls a bit.
authorAndi Gutmans <andi@php.net>
Fri, 30 Jul 1999 11:55:53 +0000 (11:55 +0000)
committerAndi Gutmans <andi@php.net>
Fri, 30 Jul 1999 11:55:53 +0000 (11:55 +0000)
  There seems to be no reason for stack->top in the ptr_stack except for
  when realloc()'in the stack. I think I'll remove it.

Zend/zend_execute.c
Zend/zend_ptr_stack.c
Zend/zend_ptr_stack.h

index e0bc6c8936b8a3562ebfbf18531ec48f53dac1f9..362b3a8c85cbaafe42904f85035a4c4f9a31bb24 100644 (file)
@@ -1304,10 +1304,12 @@ binary_assign_op_addr: {
                                        HashTable *active_function_table;
                                        zval tmp;
 
+                                       zend_ptr_stack_n_push(&EG(arg_types_stack), 3, function_being_called, object.ptr, object.ptr_ptr);
+                                       /*
                                        zend_ptr_stack_push(&EG(arg_types_stack), function_being_called); 
                                        zend_ptr_stack_push(&EG(arg_types_stack), object.ptr); 
                                        zend_ptr_stack_push(&EG(arg_types_stack), object.ptr_ptr); 
-
+                                       */
                                        if (opline->extended_value & ZEND_CTOR_CALL) {
                                                /* constructor call */
 
@@ -1465,9 +1467,12 @@ do_fcall_common:
                                                efree(function_being_called);
                                        }
                                        if (opline->opcode == ZEND_DO_FCALL_BY_NAME) {
+                                               zend_ptr_stack_n_pop(&EG(arg_types_stack), 3, &object.ptr_ptr, &object.ptr, &function_being_called);
+                                       /*
                                                object.ptr_ptr = zend_ptr_stack_pop(&EG(arg_types_stack));
                                                object.ptr = zend_ptr_stack_pop(&EG(arg_types_stack));
                                                function_being_called = zend_ptr_stack_pop(&EG(arg_types_stack));
+                                       */
                                        }
                                        function_state.function = (zend_function *) op_array;
                                        EG(function_state_ptr) = &function_state;
index 35e5be2239643361a7cb66cb4a4ae76929503de8..8cbba37eb076520ef6c6a0b3f46a08356cbce5c9 100644 (file)
 
 #include "zend.h"
 #include "zend_ptr_stack.h"
+#if HAVE_STDARG_H
+#include <stdarg.h>
+#endif
 
 
 ZEND_API void zend_ptr_stack_init(zend_ptr_stack *stack)
 {
-       stack->top_element = stack->elements = (void **) emalloc(sizeof(void *)*STACK_BLOCK_SIZE);
-       stack->max = STACK_BLOCK_SIZE;
+       stack->top_element = stack->elements = (void **) emalloc(sizeof(void *)*PTR_STACK_BLOCK_SIZE);
+       stack->max = PTR_STACK_BLOCK_SIZE;
        stack->top = 0;
 }
 
@@ -33,15 +36,49 @@ ZEND_API void zend_ptr_stack_init(zend_ptr_stack *stack)
 ZEND_API inline void zend_ptr_stack_push(zend_ptr_stack *stack, void *ptr)
 {
        if (stack->top >= stack->max) {         /* we need to allocate more memory */
-               short diff = stack->top_element-stack->elements;
-               
                stack->elements = (void **) erealloc(stack->elements, (sizeof(void *) * (stack->max *= 2 )));
-               stack->top_element = stack->elements+diff;
+               stack->top_element = stack->elements+stack->top;
        }
        stack->top++;
        *(stack->top_element++) = ptr;
 }
 
+ZEND_API inline 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;
+       }
+       va_start(ptr, count);
+       while (count>0) {
+               elem = va_arg(ptr, void *);
+               stack->top++;
+               *(stack->top_element++) = elem;
+               count--;
+       }
+       va_end(ptr);
+}
+
+
+ZEND_API inline void zend_ptr_stack_n_pop(zend_ptr_stack *stack, int count,...)
+{
+       va_list ptr;
+       void **elem;
+       
+       va_start(ptr, count);
+       while (count>0) {
+               elem = va_arg(ptr, void **);
+               *elem = *(stack->top_element--) = elem;
+               stack->top--;
+               count--;
+       }
+       va_end(ptr);
+}
 
 ZEND_API inline void *zend_ptr_stack_pop(zend_ptr_stack *stack)
 {
index 599c4c454af313f8f3782c175870a4382488539a..fd0770c647774bc5182cdeb3abf71248d6ada816 100644 (file)
@@ -28,11 +28,13 @@ typedef struct _zend_ptr_stack {
 } zend_ptr_stack;
 
 
-#define STACK_BLOCK_SIZE 64
+#define PTR_STACK_BLOCK_SIZE 64
 
 ZEND_API void zend_ptr_stack_init(zend_ptr_stack *stack);
 ZEND_API void zend_ptr_stack_push(zend_ptr_stack *stack, void *ptr);
+ZEND_API void zend_ptr_stack_n_push(zend_ptr_stack *stack, int count,...);
 ZEND_API void *zend_ptr_stack_pop(zend_ptr_stack *stack);
+ZEND_API void zend_ptr_stack_n_pop(zend_ptr_stack *stack, int count,...);
 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 *));