cvs: php4 /ext/standard array.c

From: Date: Mon, 22 Oct 2001 20:49:28 +0000
Subject: cvs: php4 /ext/standard array.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-7952@lists.php.net to get a copy of this message
rasmus Mon Oct 22 16:49:28 2001 EDT Modified files: /php4/ext/standard array.c Log: Use references instead of making a copy each time in array_init(). About twice as fast for a high number of elements. 2.80 seconds for the copy of 1,000,000 elements and 1.39s for the reference version. Need to chunk it every 62k or so because refcount is a short. Index: php4/ext/standard/array.c diff -u php4/ext/standard/array.c:1.143 php4/ext/standard/array.c:1.144 --- php4/ext/standard/array.c:1.143 Sun Oct 21 03:45:32 2001 +++ php4/ext/standard/array.c Mon Oct 22 16:49:27 2001 @@ -21,7 +21,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: array.c,v 1.143 2001/10/21 07:45:32 rasmus Exp $ */ +/* $Id: array.c,v 1.144 2001/10/22 20:49:27 rasmus Exp $ */ #include "php.h" #include "php_ini.h" @@ -1330,7 +1330,7 @@ PHP_FUNCTION(array_init) { zval **start_key, **num, **val, *newval; - int i; + long i; if (ZEND_NUM_ARGS() != 3 || zend_get_parameters_ex(3, &start_key, &num, &val) == FAILURE) { WRONG_PARAM_COUNT; @@ -1345,11 +1345,12 @@ case IS_STRING: case IS_LONG: case IS_DOUBLE: + if(PZVAL_IS_REF(*val)) { + SEPARATE_ZVAL(val); + } convert_to_long_ex(start_key); - MAKE_STD_ZVAL(newval); - *newval = **val; - zval_copy_ctor(newval); - add_index_zval(return_value, Z_LVAL_PP(start_key), newval); + zval_add_ref(val); + zend_hash_index_update(Z_ARRVAL_P(return_value), Z_LVAL_PP(start_key), val, sizeof(val), NULL); break; default: php_error(E_WARNING, "Wrong datatype for start key in array_init()"); @@ -1363,11 +1364,15 @@ php_error(E_WARNING, "Number of elements must be positive in array_init()"); RETURN_FALSE; } + newval = *val; while(i--) { - MAKE_STD_ZVAL(newval); - *newval = **val; - zval_copy_ctor(newval); - add_next_index_zval(return_value, newval); + if(!(i%62000)) { + MAKE_STD_ZVAL(newval); + *newval = **val; + zval_copy_ctor(newval); + } + zval_add_ref(&newval); + zend_hash_next_index_insert(Z_ARRVAL_P(return_value), &newval, sizeof(zval *), NULL); } } /* }}} */

« previous php.cvs (#7952) next »