com php-src: ZEND_HASH_FOREACH_* usage: ext/standar d/array.c ext/standard/string.c
| From: | Dmitry Stogov | Date: | Fri, 18 Apr 2014 17:49:07 +0000 |
| Subject: | com php-src: ZEND_HASH_FOREACH_* usage: ext/standar d/array.c ext/standard/string.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-77343@lists.php.net to get a copy of this message | ||
Commit: 277f8f6391721f5b6ddb84e9b5a8f1a57f7b1993
Author: Dmitry Stogov <dmitry@zend.com> Fri, 18 Apr 2014 21:49:07 +0400
Parents: c1e900e4c00301da002a7c879ef3ccfa92989be5
Branches: phpng
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=277f8f6391721f5b6ddb84e9b5a8f1a57f7b1993
Log:
ZEND_HASH_FOREACH_* usage
Changed paths:
M ext/standard/array.c
M ext/standard/string.c
Diff:
diff --git a/ext/standard/array.c b/ext/standard/array.c
index dfa6471..d579919 100644
--- a/ext/standard/array.c
+++ b/ext/standard/array.c
@@ -2177,7 +2177,6 @@ PHP_FUNCTION(array_slice)
pos; /* Current position in the array */
zend_string *string_key;
ulong num_key;
- HashPosition hpos;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "al|zb", &input, &offset,
&z_length, &preserve_keys) == FAILURE) {
return;
@@ -2218,33 +2217,28 @@ PHP_FUNCTION(array_slice)
/* Start at the beginning and go until we hit offset */
pos = 0;
- zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(input), &hpos);
- while (pos < offset && (entry = zend_hash_get_current_data_ex(Z_ARRVAL_P(input),
&hpos)) != NULL) {
+ ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(input), num_key, string_key, entry) {
pos++;
- zend_hash_move_forward_ex(Z_ARRVAL_P(input), &hpos);
- }
-
- /* Copy elements from input array to the one that's returned */
- while (pos < offset + length && (entry =
zend_hash_get_current_data_ex(Z_ARRVAL_P(input), &hpos)) != NULL) {
+ if (pos <= offset) {
+ continue;
+ }
+ if (pos > offset + length) {
+ break;
+ }
+ /* Copy elements from input array to the one that's returned */
zval_add_ref(entry);
- switch (zend_hash_get_current_key_ex(Z_ARRVAL_P(input), &string_key, &num_key, 0,
&hpos)) {
- case HASH_KEY_IS_STRING:
- zend_hash_update(Z_ARRVAL_P(return_value), string_key, entry);
- break;
-
- case HASH_KEY_IS_LONG:
- if (preserve_keys) {
- zend_hash_index_update(Z_ARRVAL_P(return_value), num_key, entry);
- } else {
- zend_hash_next_index_insert(Z_ARRVAL_P(return_value), entry);
- }
- break;
+ if (string_key) {
+ zend_hash_update(Z_ARRVAL_P(return_value), string_key, entry);
+ } else {
+ if (preserve_keys) {
+ zend_hash_index_update(Z_ARRVAL_P(return_value), num_key, entry);
+ } else {
+ zend_hash_next_index_insert(Z_ARRVAL_P(return_value), entry);
+ }
}
- pos++;
- zend_hash_move_forward_ex(Z_ARRVAL_P(input), &hpos);
- }
+ } ZEND_HASH_FOREACH_END();
}
/* }}} */
diff --git a/ext/standard/string.c b/ext/standard/string.c
index 8f07c33..a1ea1cb 100644
--- a/ext/standard/string.c
+++ b/ext/standard/string.c
@@ -3816,8 +3816,6 @@ static void php_str_replace_in_subject(zval *search, zval *replace, zval
*subjec
/* Duplicate subject string for repeated replacement */
ZVAL_DUP(result, subject);
- zend_hash_internal_pointer_reset(Z_ARRVAL_P(search));
-
if (Z_TYPE_P(replace) == IS_ARRAY) {
zend_hash_internal_pointer_reset(Z_ARRVAL_P(replace));
} else {
@@ -3827,12 +3825,11 @@ static void php_str_replace_in_subject(zval *search, zval *replace, zval
*subjec
}
/* For each entry in the search array, get the entry */
- while ((search_entry = zend_hash_get_current_data(Z_ARRVAL_P(search))) != NULL) {
+ ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(search), search_entry) {
/* Make sure we're dealing with strings. */
SEPARATE_ZVAL(search_entry);
convert_to_string(search_entry);
if (Z_STRLEN_P(search_entry) == 0) {
- zend_hash_move_forward(Z_ARRVAL_P(search));
if (Z_TYPE_P(replace) == IS_ARRAY) {
zend_hash_move_forward(Z_ARRVAL_P(replace));
}
@@ -3881,9 +3878,7 @@ static void php_str_replace_in_subject(zval *search, zval *replace, zval
*subjec
zval_ptr_dtor(&tmp_subject);
return;
}
-
- zend_hash_move_forward(Z_ARRVAL_P(search));
- }
+ } ZEND_HASH_FOREACH_END();
} else {
if (Z_STRLEN_P(search) == 1) {
php_char_to_str_ex(Z_STRVAL_P(subject),