Skip to content

Commit 99ad9d7

Browse files
committed
Move duplicated code into functions
1 parent c1489e7 commit 99ad9d7

File tree

1 file changed

+25
-20
lines changed

1 file changed

+25
-20
lines changed

Zend/Optimizer/zend_optimizer.c

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -793,6 +793,26 @@ void zend_optimizer_shift_jump(zend_op_array *op_array, zend_op *opline, uint32_
793793
}
794794
}
795795

796+
static bool zend_optimizer_ignore_class(zend_class_entry *ce, zend_string *filename)
797+
{
798+
return ce->type == ZEND_USER_CLASS
799+
&& !(ce->ce_flags & ZEND_ACC_PRELOADED)
800+
&& (!ce->info.user.filename || ce->info.user.filename != filename);
801+
}
802+
803+
static bool zend_optimizer_ignore_function(zend_function *fbc, zend_string *filename)
804+
{
805+
if (fbc->type == ZEND_INTERNAL_FUNCTION) {
806+
return false;
807+
} else if (fbc->type == ZEND_USER_FUNCTION) {
808+
return !(fbc->op_array.fn_flags & ZEND_ACC_PRELOADED)
809+
&& (!fbc->op_array.filename && fbc->op_array.filename != filename);
810+
} else {
811+
ZEND_ASSERT(fbc->type == ZEND_EVAL_CODE);
812+
return true;
813+
}
814+
}
815+
796816
zend_class_entry *zend_optimizer_get_class_entry(
797817
const zend_script *script, const zend_op_array *op_array, zend_string *lcname) {
798818
zend_class_entry *ce = script ? zend_hash_find_ptr(&script->class_table, lcname) : NULL;
@@ -801,10 +821,7 @@ zend_class_entry *zend_optimizer_get_class_entry(
801821
}
802822

803823
ce = zend_hash_find_ptr(CG(class_table), lcname);
804-
if (ce
805-
&& (ce->type == ZEND_INTERNAL_CLASS
806-
|| (ce->ce_flags & ZEND_ACC_PRELOADED)
807-
|| (op_array && ce->info.user.filename == op_array->filename))) {
824+
if (ce && !zend_optimizer_ignore_class(ce, op_array ? op_array->filename : NULL)) {
808825
return ce;
809826
}
810827

@@ -847,12 +864,8 @@ const zend_class_constant *zend_fetch_class_const_info(
847864
ce = zend_optimizer_get_class_entry(script, op_array, Z_STR_P(op1 + 1));
848865
} else {
849866
zend_class_entry *tmp = zend_hash_find_ptr(EG(class_table), Z_STR_P(op1 + 1));
850-
if (tmp != NULL) {
851-
if (tmp->type == ZEND_INTERNAL_CLASS
852-
|| (tmp->ce_flags & ZEND_ACC_PRELOADED)
853-
|| (tmp->info.user.filename && tmp->info.user.filename == op_array->filename)) {
854-
ce = tmp;
855-
}
867+
if (tmp != NULL && !zend_optimizer_ignore_class(tmp, op_array->filename)) {
868+
ce = tmp;
856869
}
857870
}
858871
}
@@ -900,11 +913,7 @@ zend_function *zend_optimizer_get_called_func(
900913
if (script && (func = zend_hash_find_ptr(&script->function_table, function_name)) != NULL) {
901914
return func;
902915
} else if ((func = zend_hash_find_ptr(EG(function_table), function_name)) != NULL) {
903-
if (func->type == ZEND_INTERNAL_FUNCTION) {
904-
return func;
905-
} else if (func->type == ZEND_USER_FUNCTION
906-
&& ((func->op_array.fn_flags & ZEND_ACC_PRELOADED)
907-
|| (func->op_array.filename && func->op_array.filename == op_array->filename))) {
916+
if (!zend_optimizer_ignore_function(func, op_array->filename)) {
908917
return func;
909918
}
910919
}
@@ -918,11 +927,7 @@ zend_function *zend_optimizer_get_called_func(
918927
if (script && (func = zend_hash_find_ptr(&script->function_table, Z_STR_P(function_name)))) {
919928
return func;
920929
} else if ((func = zend_hash_find_ptr(EG(function_table), Z_STR_P(function_name))) != NULL) {
921-
if (func->type == ZEND_INTERNAL_FUNCTION) {
922-
return func;
923-
} else if (func->type == ZEND_USER_FUNCTION
924-
&& ((func->op_array.fn_flags & ZEND_ACC_PRELOADED)
925-
|| (func->op_array.filename && func->op_array.filename == op_array->filename))) {
930+
if (!zend_optimizer_ignore_function(func, op_array->filename)) {
926931
return func;
927932
}
928933
}

0 commit comments

Comments
 (0)