com php-src: Improve Hash foreach macros: Zend/zend_hash.h ext/standard/array.c

From: Date: Tue, 23 Dec 2014 05:50:39 +0000
Subject: com php-src: Improve Hash foreach macros: Zend/zend_hash.h ext/standard/array.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-83833@lists.php.net to get a copy of this message
Commit: 95bb0a0f7aec46cacf6a447ded1688e6c6ff4b62 Author: Xinchen Hui <laruence@php.net> Tue, 23 Dec 2014 00:50:39 -0500 Parents: 4b26c5d004960d460606977118ad3411bea84681 Branches: master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=95bb0a0f7aec46cacf6a447ded1688e6c6ff4b62 Log: Improve Hash foreach macros Changed paths: M Zend/zend_hash.h M ext/standard/array.c Diff: diff --git a/Zend/zend_hash.h b/Zend/zend_hash.h index 81b9332..5bdfa70 100644 --- a/Zend/zend_hash.h +++ b/Zend/zend_hash.h @@ -678,6 +678,11 @@ static zend_always_inline void *zend_hash_get_current_data_ptr_ex(HashTable *ht, #define ZEND_HASH_FOREACH_STR_KEY(ht, _key) \ ZEND_HASH_FOREACH(ht, 0); \ _key = _p->key; + +#define ZEND_HASH_FOREACH_KEY_IND(ht, _h, _key) \ + ZEND_HASH_FOREACH(ht, 1); \ + _h = _p->h; \ + _key = _p->key; #define ZEND_HASH_FOREACH_KEY(ht, _h, _key) \ ZEND_HASH_FOREACH(ht, 0); \ @@ -751,6 +756,19 @@ static zend_always_inline void *zend_hash_get_current_data_ptr_ex(HashTable *ht, _key = _p->key; \ _val = _z; +#define ZEND_HASH_FOREACH_CURRENT_KEY(ht, _h, _key) \ + _h = _p->h; \ + _key = _p->key; + +#define ZEND_HASH_FOREACH_CURRENT_STR_KEY(ht, _key) \ + _key = _p->key; + +#define ZEND_HASH_FOREACH_CURRENT_NUM_KEY(ht, _h) \ + _h = _p->h; + +#define ZEND_HASH_FOREACH_CURRENT_VAL(ht, _val) \ + _val = _z; + #define ZEND_HASH_APPLY_PROTECTION(ht) \ ((ht)->u.flags & HASH_FLAG_APPLY_PROTECTION) diff --git a/ext/standard/array.c b/ext/standard/array.c index b9ccf5b..b06b058 100644 --- a/ext/standard/array.c +++ b/ext/standard/array.c @@ -1248,10 +1248,11 @@ static inline void php_search_array(INTERNAL_FUNCTION_PARAMETERS, int behavior) if (strict) { zval res; /* comparison result */ - ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(array), num_idx, str_idx, entry) { + ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(array), entry) { ZVAL_DEREF(entry); fast_is_identical_function(&res, value, entry); if (Z_TYPE(res) == IS_TRUE) { + ZEND_HASH_FOREACH_CURRENT_KEY(Z_ARRVAL_P(array), num_idx, str_idx); if (behavior == 0) { RETURN_TRUE; } else { @@ -1265,8 +1266,9 @@ static inline void php_search_array(INTERNAL_FUNCTION_PARAMETERS, int behavior) } } ZEND_HASH_FOREACH_END(); } else { - ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(array), num_idx, str_idx, entry) { + ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(array), entry) { if (fast_equal_check_function(value, entry)) { + ZEND_HASH_FOREACH_CURRENT_KEY(Z_ARRVAL_P(array), num_idx, str_idx); if (behavior == 0) { RETURN_TRUE; } else { @@ -2674,8 +2676,6 @@ PHP_FUNCTION(array_keys) { zval *input, /* Input array */ *search_value = NULL, /* Value to search for */ - *entry, /* An entry in the input array */ - res, /* Result of comparison */ new_val; /* New value */ zend_bool strict = 0; /* do strict comparison */ zend_ulong num_idx; @@ -2696,12 +2696,15 @@ PHP_FUNCTION(array_keys) /* Initialize return array */ if (search_value != NULL) { + zval *entry; /* An entry in the input array */ + zval res; /* Result of comparison */ array_init(return_value); if (strict) { - ZEND_HASH_FOREACH_KEY_VAL_IND(Z_ARRVAL_P(input), num_idx, str_idx, entry) { + ZEND_HASH_FOREACH_VAL_IND(Z_ARRVAL_P(input), entry) { fast_is_identical_function(&res, search_value, entry); if (Z_TYPE(res) == IS_TRUE) { + ZEND_HASH_FOREACH_CURRENT_KEY(Z_ARRVAL_P(input), num_idx, str_idx); if (str_idx) { ZVAL_STR_COPY(&new_val, str_idx); } else { @@ -2711,8 +2714,9 @@ PHP_FUNCTION(array_keys) } } ZEND_HASH_FOREACH_END(); } else { - ZEND_HASH_FOREACH_KEY_VAL_IND(Z_ARRVAL_P(input), num_idx, str_idx, entry) { + ZEND_HASH_FOREACH_VAL_IND(Z_ARRVAL_P(input), entry) { if (fast_equal_check_function(search_value, entry)) { + ZEND_HASH_FOREACH_CURRENT_KEY(Z_ARRVAL_P(input), num_idx, str_idx); if (str_idx) { ZVAL_STR_COPY(&new_val, str_idx); } else { @@ -2726,7 +2730,7 @@ PHP_FUNCTION(array_keys) array_init_size(return_value, zend_hash_num_elements(Z_ARRVAL_P(input))); /* Go through input array and add keys to the return array */ - ZEND_HASH_FOREACH_KEY_VAL_IND(Z_ARRVAL_P(input), num_idx, str_idx, entry) { + ZEND_HASH_FOREACH_KEY_IND(Z_ARRVAL_P(input), num_idx, str_idx) { if (str_idx) { ZVAL_STR_COPY(&new_val, str_idx); } else { @@ -2826,6 +2830,7 @@ zend_bool array_column_param_helper(zval *param, return 0; } } +/* }}} */ /* {{{ proto array array_column(array input, mixed column_key[, mixed index_key]) Return the values from a single column in the input array, identified by the @@ -4043,9 +4048,10 @@ PHP_FUNCTION(array_diff) /* copy all elements of first array that are not in exclude set */ array_init_size(return_value, zend_hash_num_elements(Z_ARRVAL(args[0]))); - ZEND_HASH_FOREACH_KEY_VAL_IND(Z_ARRVAL(args[0]), idx, key, value) { + ZEND_HASH_FOREACH_VAL_IND(Z_ARRVAL(args[0]), value) { str = zval_get_string(value); if (!zend_hash_exists(&exclude, str)) { + ZEND_HASH_FOREACH_CURRENT_KEY(Z_ARRVAL(args[0]), idx, key); if (key) { zval_add_ref(value); zend_hash_add_new(Z_ARRVAL_P(return_value), key, value);

« previous php.cvs (#83833) next »