Skip to content

Commit 4e3c75b

Browse files
committed
zend_builtin_functions.c: refactor is_a_impl() to use early returns
1 parent 38167b3 commit 4e3c75b

File tree

1 file changed

+11
-14
lines changed

1 file changed

+11
-14
lines changed

Zend/zend_builtin_functions.c

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -691,7 +691,6 @@ static void is_a_impl(INTERNAL_FUNCTION_PARAMETERS, bool only_subclass) /* {{{ *
691691
zend_string *class_name;
692692
zend_class_entry *instance_ce;
693693
bool allow_string = only_subclass;
694-
bool retval;
695694

696695
ZEND_PARSE_PARAMETERS_START(2, 3)
697696
Z_PARAM_ZVAL(obj)
@@ -718,21 +717,19 @@ static void is_a_impl(INTERNAL_FUNCTION_PARAMETERS, bool only_subclass) /* {{{ *
718717
}
719718

720719
if (!only_subclass && EXPECTED(zend_string_equals(instance_ce->name, class_name))) {
721-
retval = 1;
722-
} else {
723-
const zend_class_entry *ce = zend_lookup_class_ex(class_name, NULL, ZEND_FETCH_CLASS_NO_AUTOLOAD);
724-
if (!ce) {
725-
retval = 0;
726-
} else {
727-
if (only_subclass && instance_ce == ce) {
728-
retval = 0;
729-
} else {
730-
retval = instanceof_function(instance_ce, ce);
731-
}
732-
}
720+
RETURN_TRUE;
721+
}
722+
723+
const zend_class_entry *ce = zend_lookup_class_ex(class_name, NULL, ZEND_FETCH_CLASS_NO_AUTOLOAD);
724+
if (!ce) {
725+
RETURN_FALSE;
726+
}
727+
728+
if (only_subclass && instance_ce == ce) {
729+
RETURN_FALSE;
733730
}
734731

735-
RETURN_BOOL(retval);
732+
RETURN_BOOL(instanceof_function(instance_ce, ce));
736733
}
737734
/* }}} */
738735

0 commit comments

Comments
 (0)