Skip to content

Commit 290e520

Browse files
committed
Use ZEND_HASH_FOREACH APIs in a few more places
1 parent c9acc90 commit 290e520

File tree

3 files changed

+19
-65
lines changed

3 files changed

+19
-65
lines changed

ext/gd/gd.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4547,13 +4547,9 @@ static void php_image_filter_scatter(INTERNAL_FUNCTION_PARAMETERS)
45474547

45484548
colors = emalloc(num_colors * sizeof(int));
45494549

4550-
zend_hash_internal_pointer_reset(Z_ARRVAL_P(hash_colors));
4551-
4552-
while ((color = zend_hash_get_current_data(Z_ARRVAL_P(hash_colors))) != NULL) {
4553-
zend_hash_move_forward(Z_ARRVAL_P(hash_colors));
4554-
4550+
ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(hash_colors), color) {
45554551
*(colors + i++) = (int) zval_get_long(color);
4556-
}
4552+
} ZEND_HASH_FOREACH_END();
45574553

45584554
RETVAL_BOOL(gdImageScatterColor(im, (int)scatter_sub, (int)scatter_plus, colors, num_colors));
45594555

ext/phar/phar.c

Lines changed: 12 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1971,44 +1971,31 @@ int phar_detect_phar_fname_ext(const char *filename, size_t filename_len, const
19711971
}
19721972
} else {
19731973
zend_string *str_key;
1974-
zend_ulong unused;
19751974

1976-
for (zend_hash_internal_pointer_reset(&(PHAR_G(phar_fname_map)));
1977-
HASH_KEY_NON_EXISTENT != zend_hash_get_current_key(&(PHAR_G(phar_fname_map)), &str_key, &unused);
1978-
zend_hash_move_forward(&(PHAR_G(phar_fname_map)))
1979-
) {
1975+
ZEND_HASH_FOREACH_STR_KEY_PTR(&PHAR_G(phar_fname_map), str_key, pphar) {
19801976
if (ZSTR_LEN(str_key) > (uint32_t) filename_len) {
19811977
continue;
19821978
}
19831979

19841980
if (!memcmp(filename, ZSTR_VAL(str_key), ZSTR_LEN(str_key)) && ((uint32_t)filename_len == ZSTR_LEN(str_key)
19851981
|| filename[ZSTR_LEN(str_key)] == '/' || filename[ZSTR_LEN(str_key)] == '\0')) {
1986-
if (NULL == (pphar = zend_hash_get_current_data_ptr(&(PHAR_G(phar_fname_map))))) {
1987-
break;
1988-
}
19891982
*ext_str = filename + (ZSTR_LEN(str_key) - pphar->ext_len);
19901983
goto woohoo;
19911984
}
1992-
}
1985+
} ZEND_HASH_FOREACH_END();
19931986

19941987
if (PHAR_G(manifest_cached)) {
1995-
for (zend_hash_internal_pointer_reset(&cached_phars);
1996-
HASH_KEY_NON_EXISTENT != zend_hash_get_current_key(&cached_phars, &str_key, &unused);
1997-
zend_hash_move_forward(&cached_phars)
1998-
) {
1988+
ZEND_HASH_FOREACH_STR_KEY_PTR(&cached_phars, str_key, pphar) {
19991989
if (ZSTR_LEN(str_key) > (uint32_t) filename_len) {
20001990
continue;
20011991
}
20021992

20031993
if (!memcmp(filename, ZSTR_VAL(str_key), ZSTR_LEN(str_key)) && ((uint32_t)filename_len == ZSTR_LEN(str_key)
20041994
|| filename[ZSTR_LEN(str_key)] == '/' || filename[ZSTR_LEN(str_key)] == '\0')) {
2005-
if (NULL == (pphar = zend_hash_get_current_data_ptr(&cached_phars))) {
2006-
break;
2007-
}
20081995
*ext_str = filename + (ZSTR_LEN(str_key) - pphar->ext_len);
20091996
goto woohoo;
20101997
}
2011-
}
1998+
} ZEND_HASH_FOREACH_END();
20121999
}
20132000
}
20142001
}
@@ -2692,12 +2679,7 @@ int phar_flush(phar_archive_data *phar, char *user_stub, zend_long len, int conv
26922679
}
26932680
new_manifest_count = 0;
26942681
offset = 0;
2695-
for (zend_hash_internal_pointer_reset(&phar->manifest);
2696-
zend_hash_has_more_elements(&phar->manifest) == SUCCESS;
2697-
zend_hash_move_forward(&phar->manifest)) {
2698-
if ((entry = zend_hash_get_current_data_ptr(&phar->manifest)) == NULL) {
2699-
continue;
2700-
}
2682+
ZEND_HASH_FOREACH_PTR(&phar->manifest, entry) {
27012683
if (entry->cfp) {
27022684
/* did we forget to get rid of cfp last time? */
27032685
php_stream_close(entry->cfp);
@@ -2851,7 +2833,7 @@ int phar_flush(phar_archive_data *phar, char *user_stub, zend_long len, int conv
28512833
entry->old_flags = entry->flags;
28522834
entry->is_modified = 1;
28532835
global_flags |= (entry->flags & PHAR_ENT_COMPRESSION_MASK);
2854-
}
2836+
} ZEND_HASH_FOREACH_END();
28552837
global_flags |= PHAR_HDR_SIGNATURE;
28562838

28572839
/* write out manifest pre-header */
@@ -2932,14 +2914,7 @@ int phar_flush(phar_archive_data *phar, char *user_stub, zend_long len, int conv
29322914
manifest_ftell = php_stream_tell(newfile);
29332915

29342916
/* now write the manifest */
2935-
for (zend_hash_internal_pointer_reset(&phar->manifest);
2936-
zend_hash_has_more_elements(&phar->manifest) == SUCCESS;
2937-
zend_hash_move_forward(&phar->manifest)) {
2938-
2939-
if ((entry = zend_hash_get_current_data_ptr(&phar->manifest)) == NULL) {
2940-
continue;
2941-
}
2942-
2917+
ZEND_HASH_FOREACH_PTR(&phar->manifest, entry) {
29432918
if (entry->is_deleted || entry->is_mounted) {
29442919
/* remove this from the new phar if deleted, ignore if mounted */
29452920
continue;
@@ -3001,7 +2976,7 @@ int phar_flush(phar_archive_data *phar, char *user_stub, zend_long len, int conv
30012976

30022977
return EOF;
30032978
}
3004-
}
2979+
} ZEND_HASH_FOREACH_END();
30052980
/* Hack - see bug #65028, add padding byte to the end of the manifest */
30062981
if(manifest_hack) {
30072982
if(1 != php_stream_write(newfile, manifest, 1)) {
@@ -3021,14 +2996,7 @@ int phar_flush(phar_archive_data *phar, char *user_stub, zend_long len, int conv
30212996

30222997
/* now copy the actual file data to the new phar */
30232998
offset = php_stream_tell(newfile);
3024-
for (zend_hash_internal_pointer_reset(&phar->manifest);
3025-
zend_hash_has_more_elements(&phar->manifest) == SUCCESS;
3026-
zend_hash_move_forward(&phar->manifest)) {
3027-
3028-
if ((entry = zend_hash_get_current_data_ptr(&phar->manifest)) == NULL) {
3029-
continue;
3030-
}
3031-
2999+
ZEND_HASH_FOREACH_PTR(&phar->manifest, entry) {
30323000
if (entry->is_deleted || entry->is_dir || entry->is_mounted) {
30333001
continue;
30343002
}
@@ -3096,7 +3064,7 @@ int phar_flush(phar_archive_data *phar, char *user_stub, zend_long len, int conv
30963064
} else if (entry->fp_type == PHAR_UFP) {
30973065
entry->fp_type = PHAR_FP;
30983066
}
3099-
}
3067+
} ZEND_HASH_FOREACH_END();
31003068

31013069
/* append signature */
31023070
if (global_flags & PHAR_HDR_SIGNATURE) {
@@ -3484,11 +3452,9 @@ void phar_request_initialize(void) /* {{{ */
34843452
phar_archive_data *pphar;
34853453
phar_entry_fp *stuff = (phar_entry_fp *) ecalloc(zend_hash_num_elements(&cached_phars), sizeof(phar_entry_fp));
34863454

3487-
for (zend_hash_internal_pointer_reset(&cached_phars);
3488-
(pphar = zend_hash_get_current_data_ptr(&cached_phars)) != NULL;
3489-
zend_hash_move_forward(&cached_phars)) {
3455+
ZEND_HASH_FOREACH_PTR(&cached_phars, pphar) {
34903456
stuff[pphar->phar_pos].manifest = (phar_entry_fp_info *) ecalloc( zend_hash_num_elements(&(pphar->manifest)), sizeof(phar_entry_fp_info));
3491-
}
3457+
} ZEND_HASH_FOREACH_END();
34923458

34933459
PHAR_G(cached_fp) = stuff;
34943460
}

ext/soap/php_http.c

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -833,20 +833,13 @@ int make_http_soap_request(zval *this_ptr,
833833
Z_TYPE_P(cookies) == IS_ARRAY) {
834834
zval *data;
835835
zend_string *key;
836-
int i, n;
837-
836+
uint32_t n = zend_hash_num_elements(Z_ARRVAL_P(cookies));
838837
has_cookies = 1;
839-
n = zend_hash_num_elements(Z_ARRVAL_P(cookies));
840838
if (n > 0) {
841-
zend_hash_internal_pointer_reset(Z_ARRVAL_P(cookies));
842839
smart_str_append_const(&soap_headers, "Cookie: ");
843-
for (i = 0; i < n; i++) {
844-
zend_ulong numindx;
845-
int res = zend_hash_get_current_key(Z_ARRVAL_P(cookies), &key, &numindx);
846-
data = zend_hash_get_current_data(Z_ARRVAL_P(cookies));
847-
848-
if (res == HASH_KEY_IS_STRING && Z_TYPE_P(data) == IS_ARRAY) {
849-
zval *value;
840+
ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(cookies), key, data) {
841+
if (key && Z_TYPE_P(data) == IS_ARRAY) {
842+
zval *value;
850843

851844
if ((value = zend_hash_index_find(Z_ARRVAL_P(data), 0)) != NULL &&
852845
Z_TYPE_P(value) == IS_STRING) {
@@ -865,8 +858,7 @@ int make_http_soap_request(zval *this_ptr,
865858
}
866859
}
867860
}
868-
zend_hash_move_forward(Z_ARRVAL_P(cookies));
869-
}
861+
} ZEND_HASH_FOREACH_END();
870862
smart_str_append_const(&soap_headers, "\r\n");
871863
}
872864
}

0 commit comments

Comments
 (0)