Skip to content

Commit c42f0ba

Browse files
committed
Removed useless IS_UNDEF checks
1 parent 7c1e093 commit c42f0ba

File tree

8 files changed

+35
-59
lines changed

8 files changed

+35
-59
lines changed

Zend/zend_interfaces.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -161,11 +161,9 @@ ZEND_API int zend_user_it_valid(zend_object_iterator *_iter)
161161
int result;
162162

163163
zend_call_method_with_0_params(object, iter->ce, &iter->ce->iterator_funcs_ptr->zf_valid, "valid", &more);
164-
if (Z_TYPE(more) != IS_UNDEF) {
165-
result = i_zend_is_true(&more);
166-
zval_ptr_dtor(&more);
167-
return result ? SUCCESS : FAILURE;
168-
}
164+
result = i_zend_is_true(&more);
165+
zval_ptr_dtor(&more);
166+
return result ? SUCCESS : FAILURE;
169167
}
170168
return FAILURE;
171169
}

Zend/zend_object_handlers.c

Lines changed: 15 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -909,18 +909,12 @@ ZEND_API int zend_std_has_dimension(zval *object, zval *offset, int check_empty)
909909
ZVAL_COPY_DEREF(&tmp_offset, offset);
910910
ZVAL_COPY(&tmp_object, object);
911911
zend_call_method_with_1_params(&tmp_object, ce, NULL, "offsetexists", &retval, &tmp_offset);
912-
if (EXPECTED(Z_TYPE(retval) != IS_UNDEF)) {
912+
result = i_zend_is_true(&retval);
913+
zval_ptr_dtor(&retval);
914+
if (check_empty && result && EXPECTED(!EG(exception))) {
915+
zend_call_method_with_1_params(&tmp_object, ce, NULL, "offsetget", &retval, &tmp_offset);
913916
result = i_zend_is_true(&retval);
914917
zval_ptr_dtor(&retval);
915-
if (check_empty && result && EXPECTED(!EG(exception))) {
916-
zend_call_method_with_1_params(&tmp_object, ce, NULL, "offsetget", &retval, &tmp_offset);
917-
if (EXPECTED(Z_TYPE(retval) != IS_UNDEF)) {
918-
result = i_zend_is_true(&retval);
919-
zval_ptr_dtor(&retval);
920-
}
921-
}
922-
} else {
923-
result = 0;
924918
}
925919
zval_ptr_dtor(&tmp_object);
926920
zval_ptr_dtor(&tmp_offset);
@@ -1690,23 +1684,17 @@ ZEND_API int zend_std_has_property(zval *object, zval *member, int has_set_exist
16901684
GC_ADDREF(zobj);
16911685
(*guard) |= IN_ISSET; /* prevent circular getting */
16921686
zend_std_call_issetter(zobj, member, &rv);
1693-
if (Z_TYPE(rv) != IS_UNDEF) {
1694-
result = zend_is_true(&rv);
1695-
zval_ptr_dtor(&rv);
1696-
if (has_set_exists == ZEND_PROPERTY_NOT_EMPTY && result) {
1697-
if (EXPECTED(!EG(exception)) && zobj->ce->__get && !((*guard) & IN_GET)) {
1698-
(*guard) |= IN_GET;
1699-
zend_std_call_getter(zobj, member, &rv);
1700-
(*guard) &= ~IN_GET;
1701-
if (Z_TYPE(rv) != IS_UNDEF) {
1702-
result = i_zend_is_true(&rv);
1703-
zval_ptr_dtor(&rv);
1704-
} else {
1705-
result = 0;
1706-
}
1707-
} else {
1708-
result = 0;
1709-
}
1687+
result = zend_is_true(&rv);
1688+
zval_ptr_dtor(&rv);
1689+
if (has_set_exists == ZEND_PROPERTY_NOT_EMPTY && result) {
1690+
if (EXPECTED(!EG(exception)) && zobj->ce->__get && !((*guard) & IN_GET)) {
1691+
(*guard) |= IN_GET;
1692+
zend_std_call_getter(zobj, member, &rv);
1693+
(*guard) &= ~IN_GET;
1694+
result = i_zend_is_true(&rv);
1695+
zval_ptr_dtor(&rv);
1696+
} else {
1697+
result = 0;
17101698
}
17111699
}
17121700
(*guard) &= ~IN_ISSET;

ext/spl/spl_array.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,7 @@ static int spl_array_has_dimension_ex(int check_inherited, zval *object, zval *o
617617
zend_call_method_with_1_params(object, Z_OBJCE_P(object), &intern->fptr_offset_has, "offsetExists", &rv, offset);
618618
zval_ptr_dtor(offset);
619619

620-
if (!Z_ISUNDEF(rv) && zend_is_true(&rv)) {
620+
if (zend_is_true(&rv)) {
621621
zval_ptr_dtor(&rv);
622622
if (check_empty != 1) {
623623
return 1;

ext/spl/spl_directory.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -846,10 +846,8 @@ SPL_METHOD(DirectoryIterator, seek)
846846
while (intern->u.dir.index < pos) {
847847
int valid = 0;
848848
zend_call_method_with_0_params(&EX(This), Z_OBJCE(EX(This)), &intern->u.dir.func_valid, "valid", &retval);
849-
if (!Z_ISUNDEF(retval)) {
850-
valid = zend_is_true(&retval);
851-
zval_ptr_dtor(&retval);
852-
}
849+
valid = zend_is_true(&retval);
850+
zval_ptr_dtor(&retval);
853851
if (!valid) {
854852
zend_throw_exception_ex(spl_ce_OutOfBoundsException, 0, "Seek position " ZEND_LONG_FMT " is out of range", pos);
855853
return;

ext/spl/spl_fixedarray.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -507,15 +507,14 @@ static int spl_fixedarray_object_has_dimension(zval *object, zval *offset, int c
507507

508508
if (intern->fptr_offset_has) {
509509
zval rv;
510+
zend_bool result;
511+
510512
SEPARATE_ARG_IF_REF(offset);
511513
zend_call_method_with_1_params(object, intern->std.ce, &intern->fptr_offset_has, "offsetExists", &rv, offset);
512514
zval_ptr_dtor(offset);
513-
if (!Z_ISUNDEF(rv)) {
514-
zend_bool result = zend_is_true(&rv);
515-
zval_ptr_dtor(&rv);
516-
return result;
517-
}
518-
return 0;
515+
result = zend_is_true(&rv);
516+
zval_ptr_dtor(&rv);
517+
return result;
519518
}
520519

521520
return spl_fixedarray_object_has_dimension_helper(intern, offset, check_empty);

ext/spl/spl_iterators.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3644,12 +3644,8 @@ static int spl_iterator_func_apply(zend_object_iterator *iter, void *puser) /* {
36443644

36453645
apply_info->count++;
36463646
zend_fcall_info_call(&apply_info->fci, &apply_info->fcc, &retval, NULL);
3647-
if (Z_TYPE(retval) != IS_UNDEF) {
3648-
result = zend_is_true(&retval) ? ZEND_HASH_APPLY_KEEP : ZEND_HASH_APPLY_STOP;
3649-
zval_ptr_dtor(&retval);
3650-
} else {
3651-
result = ZEND_HASH_APPLY_STOP;
3652-
}
3647+
result = zend_is_true(&retval) ? ZEND_HASH_APPLY_KEEP : ZEND_HASH_APPLY_STOP;
3648+
zval_ptr_dtor(&retval);
36533649
return result;
36543650
}
36553651
/* }}} */

ext/standard/array.c

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6056,18 +6056,15 @@ PHP_FUNCTION(array_filter)
60566056
fci.params = args;
60576057

60586058
if (zend_call_function(&fci, &fci_cache) == SUCCESS) {
6059+
int retval_true;
6060+
60596061
zval_ptr_dtor(&args[0]);
60606062
if (use_type == ARRAY_FILTER_USE_BOTH) {
60616063
zval_ptr_dtor(&args[1]);
60626064
}
6063-
if (!Z_ISUNDEF(retval)) {
6064-
int retval_true = zend_is_true(&retval);
6065-
6066-
zval_ptr_dtor(&retval);
6067-
if (!retval_true) {
6068-
continue;
6069-
}
6070-
} else {
6065+
retval_true = zend_is_true(&retval);
6066+
zval_ptr_dtor(&retval);
6067+
if (!retval_true) {
60716068
continue;
60726069
}
60736070
} else {

main/streams/userspace.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1067,7 +1067,7 @@ static int php_userstreamop_set_option(php_stream *stream, int option, int value
10671067
php_error_docref(NULL, E_WARNING, "%s::" USERSTREAM_SET_OPTION " is not implemented!",
10681068
us->wrapper->classname);
10691069
ret = PHP_STREAM_OPTION_RETURN_ERR;
1070-
} else if (Z_TYPE(retval) != IS_UNDEF && zend_is_true(&retval)) {
1070+
} else if (zend_is_true(&retval)) {
10711071
ret = PHP_STREAM_OPTION_RETURN_OK;
10721072
} else {
10731073
ret = PHP_STREAM_OPTION_RETURN_ERR;
@@ -1512,7 +1512,7 @@ static int php_userstreamop_cast(php_stream *stream, int castas, void **retptr)
15121512
us->wrapper->classname);
15131513
break;
15141514
}
1515-
if (Z_ISUNDEF(retval) || !zend_is_true(&retval)) {
1515+
if (!zend_is_true(&retval)) {
15161516
break;
15171517
}
15181518
php_stream_from_zval_no_verify(intstream, &retval);

0 commit comments

Comments
 (0)