Skip to content

Commit bfaba83

Browse files
committed
Remove HASH_OF uses in ext/filter
It turns out that all of these places ultimately only accept arrays, not objects, so we can use Z_ARRVAL_P everywhere. Also add _deref in a few places where the hash lookup result is directly type-checked.
1 parent 9bbf996 commit bfaba83

File tree

2 files changed

+12
-15
lines changed

2 files changed

+12
-15
lines changed

ext/filter/filter.c

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -408,11 +408,11 @@ static void php_zval_filter(zval *value, zend_long filter, zend_long flags, zval
408408
filter_func.function(value, flags, options, charset);
409409

410410
handle_default:
411-
if (options && (Z_TYPE_P(options) == IS_ARRAY || Z_TYPE_P(options) == IS_OBJECT) &&
411+
if (options && Z_TYPE_P(options) == IS_ARRAY &&
412412
((flags & FILTER_NULL_ON_FAILURE && Z_TYPE_P(value) == IS_NULL) ||
413413
(!(flags & FILTER_NULL_ON_FAILURE) && Z_TYPE_P(value) == IS_FALSE))) {
414414
zval *tmp;
415-
if ((tmp = zend_hash_str_find(HASH_OF(options), "default", sizeof("default") - 1)) != NULL) {
415+
if ((tmp = zend_hash_str_find(Z_ARRVAL_P(options), "default", sizeof("default") - 1)) != NULL) {
416416
ZVAL_COPY(value, tmp);
417417
}
418418
}
@@ -613,22 +613,19 @@ static void php_filter_call(zval *filtered, zend_long filter, zval *filter_args,
613613
filter = lval;
614614
}
615615
} else if (filter_args) {
616-
if ((option = zend_hash_str_find(HASH_OF(filter_args), "filter", sizeof("filter") - 1)) != NULL) {
616+
if ((option = zend_hash_str_find(Z_ARRVAL_P(filter_args), "filter", sizeof("filter") - 1)) != NULL) {
617617
filter = zval_get_long(option);
618618
}
619619

620-
if ((option = zend_hash_str_find(HASH_OF(filter_args), "flags", sizeof("flags") - 1)) != NULL) {
620+
if ((option = zend_hash_str_find(Z_ARRVAL_P(filter_args), "flags", sizeof("flags") - 1)) != NULL) {
621621
filter_flags = zval_get_long(option);
622622

623623
if (!(filter_flags & FILTER_REQUIRE_ARRAY || filter_flags & FILTER_FORCE_ARRAY)) {
624624
filter_flags |= FILTER_REQUIRE_SCALAR;
625625
}
626626
}
627627

628-
if ((option = zend_hash_str_find(HASH_OF(filter_args), "options", sizeof("options") - 1)) != NULL) {
629-
/* avoid reference type */
630-
ZVAL_DEREF(option);
631-
628+
if ((option = zend_hash_str_find_deref(Z_ARRVAL_P(filter_args), "options", sizeof("options") - 1)) != NULL) {
632629
if (filter != FILTER_CALLBACK) {
633630
if (Z_TYPE_P(option) == IS_ARRAY) {
634631
options = option;
@@ -744,13 +741,13 @@ PHP_FUNCTION(filter_input)
744741
if (filter_args) {
745742
if (Z_TYPE_P(filter_args) == IS_LONG) {
746743
filter_flags = Z_LVAL_P(filter_args);
747-
} else if (Z_TYPE_P(filter_args) == IS_ARRAY && (option = zend_hash_str_find(HASH_OF(filter_args), "flags", sizeof("flags") - 1)) != NULL) {
744+
} else if (Z_TYPE_P(filter_args) == IS_ARRAY && (option = zend_hash_str_find(Z_ARRVAL_P(filter_args), "flags", sizeof("flags") - 1)) != NULL) {
748745
filter_flags = zval_get_long(option);
749746
}
750747
if (Z_TYPE_P(filter_args) == IS_ARRAY &&
751-
(opt = zend_hash_str_find(HASH_OF(filter_args), "options", sizeof("options") - 1)) != NULL &&
748+
(opt = zend_hash_str_find_deref(Z_ARRVAL_P(filter_args), "options", sizeof("options") - 1)) != NULL &&
752749
Z_TYPE_P(opt) == IS_ARRAY &&
753-
(def = zend_hash_str_find(HASH_OF(opt), "default", sizeof("default") - 1)) != NULL) {
750+
(def = zend_hash_str_find_deref(Z_ARRVAL_P(opt), "default", sizeof("default") - 1)) != NULL) {
754751
ZVAL_COPY(return_value, def);
755752
return;
756753
}
@@ -821,7 +818,7 @@ PHP_FUNCTION(filter_input_array)
821818
if (op) {
822819
if (Z_TYPE_P(op) == IS_LONG) {
823820
filter_flags = Z_LVAL_P(op);
824-
} else if (Z_TYPE_P(op) == IS_ARRAY && (option = zend_hash_str_find(HASH_OF(op), "flags", sizeof("flags") - 1)) != NULL) {
821+
} else if (Z_TYPE_P(op) == IS_ARRAY && (option = zend_hash_str_find(Z_ARRVAL_P(op), "flags", sizeof("flags") - 1)) != NULL) {
825822
filter_flags = zval_get_long(option);
826823
}
827824
}

ext/filter/logical_filters.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
var_name = 0; \
4040
var_name##_set = 0; \
4141
if (option_array) { \
42-
if ((option_val = zend_hash_str_find(HASH_OF(option_array), option_name, sizeof(option_name) - 1)) != NULL) { \
42+
if ((option_val = zend_hash_str_find(Z_ARRVAL_P(option_array), option_name, sizeof(option_name) - 1)) != NULL) { \
4343
var_name = zval_get_long(option_val); \
4444
var_name##_set = 1; \
4545
} \
@@ -52,7 +52,7 @@
5252
var_name##_set = 0; \
5353
var_name##_len = 0; \
5454
if (option_array) { \
55-
if ((option_val = zend_hash_str_find(HASH_OF(option_array), option_name, sizeof(option_name) - 1)) != NULL) { \
55+
if ((option_val = zend_hash_str_find_deref(Z_ARRVAL_P(option_array), option_name, sizeof(option_name) - 1)) != NULL) { \
5656
if (Z_TYPE_P(option_val) == IS_STRING) { \
5757
var_name = Z_STRVAL_P(option_val); \
5858
var_name##_len = Z_STRLEN_P(option_val); \
@@ -67,7 +67,7 @@
6767
var_name = NULL; \
6868
var_name##_set = 0; \
6969
if (option_array) { \
70-
if ((option_val = zend_hash_str_find(HASH_OF(option_array), option_name, sizeof(option_name) - 1)) != NULL) { \
70+
if ((option_val = zend_hash_str_find_deref(Z_ARRVAL_P(option_array), option_name, sizeof(option_name) - 1)) != NULL) { \
7171
if (Z_TYPE_P(option_val) == IS_STRING) { \
7272
var_name = Z_STR_P(option_val); \
7373
var_name##_set = 1; \

0 commit comments

Comments
 (0)