From: Ilia Alshanetsky Date: Mon, 2 Aug 2004 02:35:01 +0000 (+0000) Subject: A gentler (performance wise) allocation of buffer for temp variables. X-Git-Tag: PRE_ZEND_VM_DISPATCH_PATCH~281 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d746343928fc27bb5e973a8baba41441eb5ae4ac;p=php A gentler (performance wise) allocation of buffer for temp variables. --- diff --git a/Zend/zend_execute.c b/Zend/zend_execute.c index 686c71eb4a..806075694b 100644 --- a/Zend/zend_execute.c +++ b/Zend/zend_execute.c @@ -52,6 +52,7 @@ static void zend_extension_fcall_end_handler(zend_extension *extension, zend_op_ #define EX_T(offset) (*(temp_variable *)((char *) EX(Ts) + offset)) #define T(offset) (*(temp_variable *)((char *) Ts + offset)) +#define TEMP_VAR_STACK_LIMIT 2000 /* former zend_execute_locks.h */ static inline void zend_pzval_lock_func(zval *z) @@ -1330,7 +1331,11 @@ static int zend_check_symbol(zval **pz TSRMLS_DC) } #define RETURN_FROM_EXECUTE_LOOP(execute_data) \ - if (EX(Ts)) efree(EX(Ts)); \ + if (EX(op_array)->T < TEMP_VAR_STACK_LIMIT) { \ + free_alloca(EX(Ts)); \ + } else { \ + efree(EX(Ts)); \ + } \ EG(in_execution) = EX(original_in_execution); \ EG(current_execute_data) = EX(prev_execute_data); \ return 1; /* CHECK_ME */ @@ -1349,7 +1354,11 @@ ZEND_API void execute(zend_op_array *op_array TSRMLS_DC) /* Initialize execute_data */ EX(fbc) = NULL; EX(object) = NULL; - EX(Ts) = (temp_variable *) (op_array->T ? safe_emalloc(sizeof(temp_variable), op_array->T, 0) : NULL); + if (op_array->T < TEMP_VAR_STACK_LIMIT) { + EX(Ts) = (temp_variable *) do_alloca(sizeof(temp_variable) * op_array->T); + } else { + EX(Ts) = (temp_variable *) safe_emalloc(sizeof(temp_variable), op_array->T, 0); + } EX(op_array) = op_array; EX(original_in_execution) = EG(in_execution); EX(prev_execute_data) = EG(current_execute_data);