andrei Thu Jul 20 20:54:23 2006 UTC Modified files: /php-src unicode-progress.txt /ZendEngine2 zend_API.h zend_execute_API.c /php-src/ext/standard array.c Log: Rewrite array_map() to use params API with fci cache and mark it with U.
http://cvs.php.net/viewvc.cgi/php-src/unicode-progress.txt?r1=1.26&r2=1.27&diff_format=u Index: php-src/unicode-progress.txt diff -u php-src/unicode-progress.txt:1.26 php-src/unicode-progress.txt:1.27 --- php-src/unicode-progress.txt:1.26 Mon Jul 17 22:18:08 2006 +++ php-src/unicode-progress.txt Thu Jul 20 20:54:22 2006 @@ -22,9 +22,6 @@ Should work with minor cleanups provided that underlying comparison functions are fixed, FCI cache, test - array_map() - Params API, FCI cache, test - array_multisort() Add SORT_LOCALE_STRING, test @@ -56,6 +53,7 @@ array_flip() array_key_exists() array_keys() + array_map() array_merge() array_merge_recursive() array_product() http://cvs.php.net/viewvc.cgi/ZendEngine2/zend_API.h?r1=1.249&r2=1.250&diff_format=u Index: ZendEngine2/zend_API.h diff -u ZendEngine2/zend_API.h:1.249 ZendEngine2/zend_API.h:1.250 --- ZendEngine2/zend_API.h:1.249 Tue Jul 18 09:08:05 2006 +++ ZendEngine2/zend_API.h Thu Jul 20 20:54:22 2006 @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_API.h,v 1.249 2006/07/18 09:08:05 dmitry Exp $ */ +/* $Id: zend_API.h,v 1.250 2006/07/20 20:54:22 andrei Exp $ */ #ifndef ZEND_API_H #define ZEND_API_H @@ -162,6 +162,8 @@ # define CE_STATIC_MEMBERS(ce) ((ce)->static_members) #endif +#define ZEND_FCI_INITIALIZED(fci) ((fci).size != 0) + int zend_next_free_module(void); BEGIN_EXTERN_C() http://cvs.php.net/viewvc.cgi/ZendEngine2/zend_execute_API.c?r1=1.377&r2=1.378&diff_format=u Index: ZendEngine2/zend_execute_API.c diff -u ZendEngine2/zend_execute_API.c:1.377 ZendEngine2/zend_execute_API.c:1.378 --- ZendEngine2/zend_execute_API.c:1.377 Tue Jul 18 17:52:44 2006 +++ ZendEngine2/zend_execute_API.c Thu Jul 20 20:54:22 2006 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_execute_API.c,v 1.377 2006/07/18 17:52:44 andrei Exp $ */ +/* $Id: zend_execute_API.c,v 1.378 2006/07/20 20:54:22 andrei Exp $ */ #include <stdio.h> #include <signal.h> @@ -39,7 +39,7 @@ ZEND_API void (*zend_execute_internal)(zend_execute_data *execute_data_ptr, int return_value_used TSRMLS_DC); /* true globals */ -ZEND_API zend_fcall_info empty_fcall_info = { sizeof(zend_fcall_info), NULL, NULL, NULL, 0, NULL, NULL, 0 }; +ZEND_API zend_fcall_info empty_fcall_info = { 0, NULL, NULL, NULL, 0, NULL, NULL, 0 }; ZEND_API zend_fcall_info_cache empty_fcall_info_cache = { 0, NULL, NULL, NULL }; #ifdef ZEND_WIN32 http://cvs.php.net/viewvc.cgi/php-src/ext/standard/array.c?r1=1.368&r2=1.369&diff_format=u Index: php-src/ext/standard/array.c diff -u php-src/ext/standard/array.c:1.368 php-src/ext/standard/array.c:1.369 --- php-src/ext/standard/array.c:1.368 Mon Jul 17 22:18:01 2006 +++ php-src/ext/standard/array.c Thu Jul 20 20:54:23 2006 @@ -21,7 +21,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: array.c,v 1.368 2006/07/17 22:18:01 andrei Exp $ */ +/* $Id: array.c,v 1.369 2006/07/20 20:54:23 andrei Exp $ */ #include "php.h" #include "php_ini.h" @@ -4238,72 +4238,54 @@ /* }}} */ -/* {{{ proto array array_map(mixed callback, array input1 [, array input2 ,...]) +/* {{{ proto array array_map(mixed callback, array input1 [, array input2 ,...]) U Applies the callback to the elements in given arrays. */ PHP_FUNCTION(array_map) { - zval ***pargs = NULL; + zval ***arrays = NULL; + int n_arrays = 0; zval ***params; - zval *callback; zval *result, *null; HashPosition *array_pos; zval **args; - zval callback_name; + zend_fcall_info fci = empty_fcall_info; zend_fcall_info_cache fci_cache = empty_fcall_info_cache; int i, k, maxlen = 0; int *array_len; - if (ZEND_NUM_ARGS() < 2) { - WRONG_PARAM_COUNT; + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "f!+", &fci, &fci_cache, &arrays, &n_arrays) == FAILURE) { + return; } RETVAL_NULL(); - pargs = (zval ***)safe_emalloc(ZEND_NUM_ARGS(), sizeof(zval **), 0); - if (zend_get_parameters_array_ex(ZEND_NUM_ARGS(), pargs) == FAILURE) { - efree(pargs); - WRONG_PARAM_COUNT; - } - - callback = *pargs[0]; - - if (Z_TYPE_P(callback) != IS_NULL) { - if (!zend_is_callable(callback, 0, &callback_name)) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "The first argument, '%R', should be either NULL or a valid callback", Z_TYPE(callback_name), Z_UNIVAL(callback_name)); - zval_dtor(&callback_name); - efree(pargs); - return; - } - zval_dtor(&callback_name); - } - - args = (zval **)safe_emalloc(ZEND_NUM_ARGS(), sizeof(zval *), 0); - array_len = (int *)safe_emalloc(ZEND_NUM_ARGS(), sizeof(int), 0); - array_pos = (HashPosition *)safe_emalloc(ZEND_NUM_ARGS(), sizeof(HashPosition), 0); - - for (i = 1; i < ZEND_NUM_ARGS(); i++) { - if (Z_TYPE_PP(pargs[i]) != IS_ARRAY) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Argument #%d should be an array", i + 1); - efree(pargs); + args = (zval **)safe_emalloc(n_arrays, sizeof(zval *), 0); + array_len = (int *)safe_emalloc(n_arrays, sizeof(int), 0); + array_pos = (HashPosition *)safe_emalloc(n_arrays, sizeof(HashPosition), 0); + + for (i = 0; i < n_arrays; i++) { + if (Z_TYPE_PP(arrays[i]) != IS_ARRAY) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Argument #%d should be an array", i + 2); + efree(arrays); efree(args); efree(array_len); efree(array_pos); return; } - SEPARATE_ZVAL_IF_NOT_REF(pargs[i]); - args[i] = *pargs[i]; - array_len[i] = zend_hash_num_elements(Z_ARRVAL_PP(pargs[i])); + SEPARATE_ZVAL_IF_NOT_REF(arrays[i]); + args[i] = *arrays[i]; + array_len[i] = zend_hash_num_elements(Z_ARRVAL_PP(arrays[i])); if (array_len[i] > maxlen) { maxlen = array_len[i]; } - zend_hash_internal_pointer_reset_ex(Z_ARRVAL_PP(pargs[i]), &array_pos[i]); + zend_hash_internal_pointer_reset_ex(Z_ARRVAL_PP(arrays[i]), &array_pos[i]); } - efree(pargs); + efree(arrays); /* Short-circuit: if no callback and only one array, just return it. */ - if (Z_TYPE_P(callback) == IS_NULL && ZEND_NUM_ARGS() == 2) { - RETVAL_ZVAL(args[1], 1, 0); + if (!ZEND_FCI_INITIALIZED(fci) && n_arrays == 1) { + RETVAL_ZVAL(args[0], 1, 0); efree(array_len); efree(array_pos); efree(args); @@ -4311,7 +4293,7 @@ } array_init(return_value); - params = (zval ***)safe_emalloc(ZEND_NUM_ARGS(), sizeof(zval **), 0); + params = (zval ***)safe_emalloc(n_arrays, sizeof(zval **), 0); MAKE_STD_ZVAL(null); ZVAL_NULL(null); @@ -4326,14 +4308,14 @@ * If no callback, the result will be an array, consisting of current * entries from all arrays. */ - if (Z_TYPE_P(callback) == IS_NULL) { + if (!ZEND_FCI_INITIALIZED(fci)) { MAKE_STD_ZVAL(result); array_init(result); } - for (i = 1; i < ZEND_NUM_ARGS(); i++) { + for (i = 0; i < n_arrays; i++) { /* - * If this array still hash elements, add the current one to the + * If this array still has elements, add the current one to the * parameter list, otherwise use null value. */ if (k < array_len[i]) { @@ -4343,8 +4325,8 @@ * It is safe to store only last value of key type, because * this loop will run just once if there is only 1 array. */ - if (ZEND_NUM_ARGS() == 2) { - key_type = zend_hash_get_current_key_ex(Z_ARRVAL_P(args[1]), &str_key, &str_key_len, &num_key, 0, &array_pos[i]); + if (n_arrays == 1) { + key_type = zend_hash_get_current_key_ex(Z_ARRVAL_P(args[0]), &str_key, &str_key_len, &num_key, 0, &array_pos[i]); } zend_hash_move_forward_ex(Z_ARRVAL_P(args[i]), &array_pos[i]); @@ -4352,23 +4334,16 @@ params[i] = &null; } - if (Z_TYPE_P(callback) == IS_NULL) { + if (!ZEND_FCI_INITIALIZED(fci)) { zval_add_ref(params[i]); add_next_index_zval(result, *params[i]); } } - if (Z_TYPE_P(callback) != IS_NULL) { - zend_fcall_info fci; - - fci.size = sizeof(fci); - fci.function_table = EG(function_table); - fci.function_name = callback; - fci.symbol_table = NULL; - fci.object_pp = NULL; + if (ZEND_FCI_INITIALIZED(fci)) { fci.retval_ptr_ptr = &result; - fci.param_count = ZEND_NUM_ARGS()-1; - fci.params = ¶ms[1]; + fci.param_count = n_arrays; + fci.params = params; fci.no_separation = 0; if (zend_call_function(&fci, &fci_cache TSRMLS_CC) != SUCCESS || !result) { @@ -4381,7 +4356,7 @@ } } - if (ZEND_NUM_ARGS() > 2) { + if (n_arrays > 1) { add_next_index_zval(return_value, result); } else { zend_uchar utype;
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php