From: Andi Gutmans Date: Fri, 30 Jul 2004 20:16:40 +0000 (+0000) Subject: - Improve performance by inlining zend_ptr_stack_n_push(). var_args can X-Git-Tag: PRE_ZEND_VM_DISPATCH_PATCH~302 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=138ef9a43e9320a412a40908a8733f66aa4858c7;p=php - Improve performance by inlining zend_ptr_stack_n_push(). var_args can usually not be inlined by compilers. --- diff --git a/Zend/zend_alloc.c b/Zend/zend_alloc.c index b234bc8203..aa152fb7eb 100644 --- a/Zend/zend_alloc.c +++ b/Zend/zend_alloc.c @@ -800,7 +800,6 @@ ZEND_API void _full_mem_check(int silent ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_D } #endif - /* * Local variables: * tab-width: 4 diff --git a/Zend/zend_alloc.h b/Zend/zend_alloc.h index 1cc09385bd..3934a383a6 100644 --- a/Zend/zend_alloc.h +++ b/Zend/zend_alloc.h @@ -140,7 +140,6 @@ void zend_debug_alloc_output(char *format, ...); #define full_mem_check(silent) #endif - END_EXTERN_C() #endif diff --git a/Zend/zend_execute.c b/Zend/zend_execute.c index 093cd0812e..9b78925491 100644 --- a/Zend/zend_execute.c +++ b/Zend/zend_execute.c @@ -2451,7 +2451,7 @@ int zend_fetch_class_handler(ZEND_OPCODE_HANDLER_ARGS) int zend_init_ctor_call_handler(ZEND_OPCODE_HANDLER_ARGS) { - zend_ptr_stack_n_push(&EG(arg_types_stack), 3, EX(fbc), EX(object), EX(calling_scope)); + zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), EX(calling_scope)); if (opline->op1.op_type == IS_VAR) { SELECTIVE_PZVAL_LOCK(*EX_T(opline->op1.u.var).var.ptr_ptr, &opline->op1); @@ -2481,7 +2481,7 @@ int zend_init_method_call_handler(ZEND_OPCODE_HANDLER_ARGS) char *function_name_strval; int function_name_strlen; - zend_ptr_stack_n_push(&EG(arg_types_stack), 3, EX(fbc), EX(object), EX(calling_scope)); + zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), EX(calling_scope)); function_name = get_zval_ptr(&opline->op2, EX(Ts), &EG(free_op2), BP_VAR_R); @@ -2542,7 +2542,7 @@ int zend_init_static_method_call_handler(ZEND_OPCODE_HANDLER_ARGS) zval *function_name; zend_class_entry *ce; - zend_ptr_stack_n_push(&EG(arg_types_stack), 3, EX(fbc), EX(object), EX(calling_scope)); + zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), EX(calling_scope)); ce = EX_T(opline->op1.u.var).class_entry; if(opline->op2.op_type != IS_UNUSED) { @@ -2597,7 +2597,7 @@ int zend_init_fcall_by_name_handler(ZEND_OPCODE_HANDLER_ARGS) char *function_name_strval, *lcname; int function_name_strlen; - zend_ptr_stack_n_push(&EG(arg_types_stack), 3, EX(fbc), EX(object), EX(calling_scope)); + zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), EX(calling_scope)); is_const = (opline->op2.op_type == IS_CONST); @@ -2818,7 +2818,7 @@ int zend_do_fcall_handler(ZEND_OPCODE_HANDLER_ARGS) { zval *fname = get_zval_ptr(&opline->op1, EX(Ts), &EG(free_op1), BP_VAR_R); - zend_ptr_stack_n_push(&EG(arg_types_stack), 3, EX(fbc), EX(object), EX(calling_scope)); + zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), EX(calling_scope)); if (zend_hash_find(EG(function_table), fname->value.str.val, fname->value.str.len+1, (void **) &EX(function_state).function)==FAILURE) { zend_error(E_ERROR, "Unknown function: %s()\n", fname->value.str.val); diff --git a/Zend/zend_fast_cache.h b/Zend/zend_fast_cache.h index 2d5011e713..0ed3c0279d 100644 --- a/Zend/zend_fast_cache.h +++ b/Zend/zend_fast_cache.h @@ -104,7 +104,6 @@ typedef struct _zend_fast_cache_list_entry { - /* fast cache for zval's */ #define ALLOC_ZVAL(z) \ ZEND_FAST_ALLOC(z, zval, ZVAL_CACHE_LIST) diff --git a/Zend/zend_ptr_stack.h b/Zend/zend_ptr_stack.h index 4a77b024eb..d94be35257 100644 --- a/Zend/zend_ptr_stack.h +++ b/Zend/zend_ptr_stack.h @@ -39,6 +39,46 @@ 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); + + +/* 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. */ +static inline void zend_ptr_stack_3_push(zend_ptr_stack *stack, void *a, void *b, void *c) +{ +#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; + } + + stack->top += ZEND_PTR_STACK_NUM_ARGS; + *(stack->top_element++) = a; + *(stack->top_element++) = b; + *(stack->top_element++) = c; + +#undef ZEND_PTR_STACK_NUM_ARGS +} + +/* +ZEND_API 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); + stack->top--; + count--; + } + va_end(ptr); +} +*/ + END_EXTERN_C() static inline void zend_ptr_stack_push(zend_ptr_stack *stack, void *ptr)