Skip to content

Commit d77b74a

Browse files
committed
Use ZEND_HASH_FOREACH
1 parent 33870c5 commit d77b74a

File tree

1 file changed

+15
-34
lines changed

1 file changed

+15
-34
lines changed

ext/opcache/Optimizer/zend_optimizer.c

Lines changed: 15 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -748,10 +748,9 @@ static void zend_adjust_fcall_stack_size_graph(zend_op_array *op_array)
748748

749749
int zend_optimize_script(zend_script *script, zend_long optimization_level, zend_long debug_level)
750750
{
751-
uint idx, j;
752-
Bucket *p, *q;
753751
zend_class_entry *ce;
754752
zend_op_array *op_array;
753+
zend_string *name;
755754
zend_optimizer_ctx ctx;
756755
zend_call_graph call_graph;
757756

@@ -763,33 +762,24 @@ int zend_optimize_script(zend_script *script, zend_long optimization_level, zend
763762

764763
zend_optimize_op_array(&script->main_op_array, &ctx);
765764

766-
for (idx = 0; idx < script->function_table.nNumUsed; idx++) {
767-
p = script->function_table.arData + idx;
768-
if (Z_TYPE(p->val) == IS_UNDEF) continue;
769-
op_array = (zend_op_array*)Z_PTR(p->val);
765+
ZEND_HASH_FOREACH_PTR(&script->function_table, op_array) {
770766
zend_optimize_op_array(op_array, &ctx);
771-
}
767+
} ZEND_HASH_FOREACH_END();
772768

773-
for (idx = 0; idx < script->class_table.nNumUsed; idx++) {
774-
p = script->class_table.arData + idx;
775-
if (Z_TYPE(p->val) == IS_UNDEF) continue;
776-
ce = (zend_class_entry*)Z_PTR(p->val);
777-
for (j = 0; j < ce->function_table.nNumUsed; j++) {
778-
q = ce->function_table.arData + j;
779-
if (Z_TYPE(q->val) == IS_UNDEF) continue;
780-
op_array = (zend_op_array*)Z_PTR(q->val);
769+
ZEND_HASH_FOREACH_PTR(&script->class_table, ce) {
770+
ZEND_HASH_FOREACH_STR_KEY_PTR(&ce->function_table, name, op_array) {
781771
if (op_array->scope == ce) {
782772
zend_optimize_op_array(op_array, &ctx);
783773
} else if (op_array->type == ZEND_USER_FUNCTION) {
784774
zend_op_array *orig_op_array;
785-
if ((orig_op_array = zend_hash_find_ptr(&op_array->scope->function_table, q->key)) != NULL) {
775+
if ((orig_op_array = zend_hash_find_ptr(&op_array->scope->function_table, name)) != NULL) {
786776
HashTable *ht = op_array->static_variables;
787777
*op_array = *orig_op_array;
788778
op_array->static_variables = ht;
789779
}
790780
}
791-
}
792-
}
781+
} ZEND_HASH_FOREACH_END();
782+
} ZEND_HASH_FOREACH_END();
793783

794784
#if HAVE_DFA_PASS
795785
if ((ZEND_OPTIMIZER_PASS_6 & optimization_level) &&
@@ -844,33 +834,24 @@ int zend_optimize_script(zend_script *script, zend_long optimization_level, zend
844834
if (ZEND_OPTIMIZER_PASS_12 & optimization_level) {
845835
zend_adjust_fcall_stack_size(&script->main_op_array, &ctx);
846836

847-
for (idx = 0; idx < script->function_table.nNumUsed; idx++) {
848-
p = script->function_table.arData + idx;
849-
if (Z_TYPE(p->val) == IS_UNDEF) continue;
850-
op_array = (zend_op_array*)Z_PTR(p->val);
837+
ZEND_HASH_FOREACH_PTR(&script->function_table, op_array) {
851838
zend_adjust_fcall_stack_size(op_array, &ctx);
852-
}
839+
} ZEND_HASH_FOREACH_END();
853840

854-
for (idx = 0; idx < script->class_table.nNumUsed; idx++) {
855-
p = script->class_table.arData + idx;
856-
if (Z_TYPE(p->val) == IS_UNDEF) continue;
857-
ce = (zend_class_entry*)Z_PTR(p->val);
858-
for (j = 0; j < ce->function_table.nNumUsed; j++) {
859-
q = ce->function_table.arData + j;
860-
if (Z_TYPE(q->val) == IS_UNDEF) continue;
861-
op_array = (zend_op_array*)Z_PTR(q->val);
841+
ZEND_HASH_FOREACH_PTR(&script->class_table, ce) {
842+
ZEND_HASH_FOREACH_STR_KEY_PTR(&ce->function_table, name, op_array) {
862843
if (op_array->scope == ce) {
863844
zend_adjust_fcall_stack_size(op_array, &ctx);
864845
} else if (op_array->type == ZEND_USER_FUNCTION) {
865846
zend_op_array *orig_op_array;
866-
if ((orig_op_array = zend_hash_find_ptr(&op_array->scope->function_table, q->key)) != NULL) {
847+
if ((orig_op_array = zend_hash_find_ptr(&op_array->scope->function_table, name)) != NULL) {
867848
HashTable *ht = op_array->static_variables;
868849
*op_array = *orig_op_array;
869850
op_array->static_variables = ht;
870851
}
871852
}
872-
}
873-
}
853+
} ZEND_HASH_FOREACH_END();
854+
} ZEND_HASH_FOREACH_END();
874855
}
875856

876857
if (ctx.constants) {

0 commit comments

Comments
 (0)