@@ -4140,19 +4140,26 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_FE_RESET_R_SPEC_CONST_HANDLER(
4140
4140
ZEND_VM_NEXT_OPCODE();
4141
4141
} else if (IS_CONST != IS_CONST && EXPECTED(Z_TYPE_P(array_ptr) == IS_OBJECT)) {
4142
4142
if (!Z_OBJCE_P(array_ptr)->get_iterator) {
4143
- result = EX_VAR(opline->result.var);
4144
- ZVAL_COPY_VALUE(result, array_ptr);
4145
- if (IS_CONST != IS_TMP_VAR) {
4146
- Z_ADDREF_P(array_ptr);
4147
- }
4143
+ HashTable *properties;
4148
4144
if (Z_OBJ_P(array_ptr)->properties
4149
4145
&& UNEXPECTED(GC_REFCOUNT(Z_OBJ_P(array_ptr)->properties) > 1)) {
4150
4146
if (EXPECTED(!(GC_FLAGS(Z_OBJ_P(array_ptr)->properties) & IS_ARRAY_IMMUTABLE))) {
4151
4147
GC_DELREF(Z_OBJ_P(array_ptr)->properties);
4152
4148
}
4153
4149
Z_OBJ_P(array_ptr)->properties = zend_array_dup(Z_OBJ_P(array_ptr)->properties);
4154
4150
}
4155
- Z_FE_ITER_P(EX_VAR(opline->result.var)) = zend_hash_iterator_add(Z_OBJPROP_P(array_ptr), 0);
4151
+
4152
+ properties = Z_OBJPROP_P(array_ptr);
4153
+ if (zend_hash_num_elements(properties) == 0) {
4154
+ goto fe_reset_r_empty;
4155
+ }
4156
+
4157
+ result = EX_VAR(opline->result.var);
4158
+ ZVAL_COPY_VALUE(result, array_ptr);
4159
+ if (IS_CONST != IS_TMP_VAR) {
4160
+ Z_ADDREF_P(array_ptr);
4161
+ }
4162
+ Z_FE_ITER_P(result) = zend_hash_iterator_add(properties, 0);
4156
4163
4157
4164
ZEND_VM_NEXT_OPCODE_CHECK_EXCEPTION();
4158
4165
} else {
@@ -4168,6 +4175,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_FE_RESET_R_SPEC_CONST_HANDLER(
4168
4175
}
4169
4176
} else {
4170
4177
zend_error(E_WARNING, "Invalid argument supplied for foreach()");
4178
+ fe_reset_r_empty:
4171
4179
ZVAL_UNDEF(EX_VAR(opline->result.var));
4172
4180
Z_FE_ITER_P(EX_VAR(opline->result.var)) = (uint32_t)-1;
4173
4181
@@ -4218,6 +4226,7 @@ static ZEND_VM_COLD ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_FE_RESET_RW_SPEC_
4218
4226
ZEND_VM_NEXT_OPCODE();
4219
4227
} else if (IS_CONST != IS_CONST && EXPECTED(Z_TYPE_P(array_ptr) == IS_OBJECT)) {
4220
4228
if (!Z_OBJCE_P(array_ptr)->get_iterator) {
4229
+ HashTable *properties;
4221
4230
if (IS_CONST == IS_VAR || IS_CONST == IS_CV) {
4222
4231
if (array_ptr == array_ref) {
4223
4232
ZVAL_NEW_REF(array_ref, array_ref);
@@ -4236,7 +4245,14 @@ static ZEND_VM_COLD ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_FE_RESET_RW_SPEC_
4236
4245
}
4237
4246
Z_OBJ_P(array_ptr)->properties = zend_array_dup(Z_OBJ_P(array_ptr)->properties);
4238
4247
}
4239
- Z_FE_ITER_P(EX_VAR(opline->result.var)) = zend_hash_iterator_add(Z_OBJPROP_P(array_ptr), 0);
4248
+
4249
+ properties = Z_OBJPROP_P(array_ptr);
4250
+ if (zend_hash_num_elements(properties) == 0) {
4251
+ Z_FE_ITER_P(EX_VAR(opline->result.var)) = (uint32_t) -1;
4252
+ ZEND_VM_JMP(OP_JMP_ADDR(opline, opline->op2));
4253
+ }
4254
+
4255
+ Z_FE_ITER_P(EX_VAR(opline->result.var)) = zend_hash_iterator_add(properties, 0);
4240
4256
4241
4257
ZEND_VM_NEXT_OPCODE_CHECK_EXCEPTION();
4242
4258
} else {
@@ -18192,19 +18208,26 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_FE_RESET_R_SPEC_TMP_HANDLER(ZE
18192
18208
ZEND_VM_NEXT_OPCODE();
18193
18209
} else if (IS_TMP_VAR != IS_CONST && EXPECTED(Z_TYPE_P(array_ptr) == IS_OBJECT)) {
18194
18210
if (!Z_OBJCE_P(array_ptr)->get_iterator) {
18195
- result = EX_VAR(opline->result.var);
18196
- ZVAL_COPY_VALUE(result, array_ptr);
18197
- if (IS_TMP_VAR != IS_TMP_VAR) {
18198
- Z_ADDREF_P(array_ptr);
18199
- }
18211
+ HashTable *properties;
18200
18212
if (Z_OBJ_P(array_ptr)->properties
18201
18213
&& UNEXPECTED(GC_REFCOUNT(Z_OBJ_P(array_ptr)->properties) > 1)) {
18202
18214
if (EXPECTED(!(GC_FLAGS(Z_OBJ_P(array_ptr)->properties) & IS_ARRAY_IMMUTABLE))) {
18203
18215
GC_DELREF(Z_OBJ_P(array_ptr)->properties);
18204
18216
}
18205
18217
Z_OBJ_P(array_ptr)->properties = zend_array_dup(Z_OBJ_P(array_ptr)->properties);
18206
18218
}
18207
- Z_FE_ITER_P(EX_VAR(opline->result.var)) = zend_hash_iterator_add(Z_OBJPROP_P(array_ptr), 0);
18219
+
18220
+ properties = Z_OBJPROP_P(array_ptr);
18221
+ if (zend_hash_num_elements(properties) == 0) {
18222
+ goto fe_reset_r_empty;
18223
+ }
18224
+
18225
+ result = EX_VAR(opline->result.var);
18226
+ ZVAL_COPY_VALUE(result, array_ptr);
18227
+ if (IS_TMP_VAR != IS_TMP_VAR) {
18228
+ Z_ADDREF_P(array_ptr);
18229
+ }
18230
+ Z_FE_ITER_P(result) = zend_hash_iterator_add(properties, 0);
18208
18231
18209
18232
ZEND_VM_NEXT_OPCODE_CHECK_EXCEPTION();
18210
18233
} else {
@@ -18221,6 +18244,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_FE_RESET_R_SPEC_TMP_HANDLER(ZE
18221
18244
}
18222
18245
} else {
18223
18246
zend_error(E_WARNING, "Invalid argument supplied for foreach()");
18247
+ fe_reset_r_empty:
18224
18248
ZVAL_UNDEF(EX_VAR(opline->result.var));
18225
18249
Z_FE_ITER_P(EX_VAR(opline->result.var)) = (uint32_t)-1;
18226
18250
zval_ptr_dtor_nogc(free_op1);
@@ -18271,6 +18295,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_FE_RESET_RW_SPEC_TMP_HANDLER(Z
18271
18295
ZEND_VM_NEXT_OPCODE();
18272
18296
} else if (IS_TMP_VAR != IS_CONST && EXPECTED(Z_TYPE_P(array_ptr) == IS_OBJECT)) {
18273
18297
if (!Z_OBJCE_P(array_ptr)->get_iterator) {
18298
+ HashTable *properties;
18274
18299
if (IS_TMP_VAR == IS_VAR || IS_TMP_VAR == IS_CV) {
18275
18300
if (array_ptr == array_ref) {
18276
18301
ZVAL_NEW_REF(array_ref, array_ref);
@@ -18289,7 +18314,14 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_FE_RESET_RW_SPEC_TMP_HANDLER(Z
18289
18314
}
18290
18315
Z_OBJ_P(array_ptr)->properties = zend_array_dup(Z_OBJ_P(array_ptr)->properties);
18291
18316
}
18292
- Z_FE_ITER_P(EX_VAR(opline->result.var)) = zend_hash_iterator_add(Z_OBJPROP_P(array_ptr), 0);
18317
+
18318
+ properties = Z_OBJPROP_P(array_ptr);
18319
+ if (zend_hash_num_elements(properties) == 0) {
18320
+ Z_FE_ITER_P(EX_VAR(opline->result.var)) = (uint32_t) -1;
18321
+ ZEND_VM_JMP(OP_JMP_ADDR(opline, opline->op2));
18322
+ }
18323
+
18324
+ Z_FE_ITER_P(EX_VAR(opline->result.var)) = zend_hash_iterator_add(properties, 0);
18293
18325
18294
18326
ZEND_VM_NEXT_OPCODE_CHECK_EXCEPTION();
18295
18327
} else {
@@ -21282,20 +21314,26 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_FE_RESET_R_SPEC_VAR_HANDLER(ZE
21282
21314
ZEND_VM_NEXT_OPCODE();
21283
21315
} else if (IS_VAR != IS_CONST && EXPECTED(Z_TYPE_P(array_ptr) == IS_OBJECT)) {
21284
21316
if (!Z_OBJCE_P(array_ptr)->get_iterator) {
21285
- result = EX_VAR(opline->result.var);
21286
- ZVAL_COPY_VALUE(result, array_ptr);
21287
- if (IS_VAR != IS_TMP_VAR) {
21288
- Z_ADDREF_P(array_ptr);
21289
- }
21317
+ HashTable *properties;
21290
21318
if (Z_OBJ_P(array_ptr)->properties
21291
21319
&& UNEXPECTED(GC_REFCOUNT(Z_OBJ_P(array_ptr)->properties) > 1)) {
21292
21320
if (EXPECTED(!(GC_FLAGS(Z_OBJ_P(array_ptr)->properties) & IS_ARRAY_IMMUTABLE))) {
21293
21321
GC_DELREF(Z_OBJ_P(array_ptr)->properties);
21294
21322
}
21295
21323
Z_OBJ_P(array_ptr)->properties = zend_array_dup(Z_OBJ_P(array_ptr)->properties);
21296
21324
}
21297
- Z_FE_ITER_P(EX_VAR(opline->result.var)) = zend_hash_iterator_add(Z_OBJPROP_P(array_ptr), 0);
21298
21325
21326
+ properties = Z_OBJPROP_P(array_ptr);
21327
+ if (zend_hash_num_elements(properties) == 0) {
21328
+ goto fe_reset_r_empty;
21329
+ }
21330
+
21331
+ result = EX_VAR(opline->result.var);
21332
+ ZVAL_COPY_VALUE(result, array_ptr);
21333
+ if (IS_VAR != IS_TMP_VAR) {
21334
+ Z_ADDREF_P(array_ptr);
21335
+ }
21336
+ Z_FE_ITER_P(result) = zend_hash_iterator_add(properties, 0);
21299
21337
zval_ptr_dtor_nogc(free_op1);
21300
21338
ZEND_VM_NEXT_OPCODE_CHECK_EXCEPTION();
21301
21339
} else {
@@ -21312,6 +21350,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_FE_RESET_R_SPEC_VAR_HANDLER(ZE
21312
21350
}
21313
21351
} else {
21314
21352
zend_error(E_WARNING, "Invalid argument supplied for foreach()");
21353
+ fe_reset_r_empty:
21315
21354
ZVAL_UNDEF(EX_VAR(opline->result.var));
21316
21355
Z_FE_ITER_P(EX_VAR(opline->result.var)) = (uint32_t)-1;
21317
21356
zval_ptr_dtor_nogc(free_op1);
@@ -21362,6 +21401,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_FE_RESET_RW_SPEC_VAR_HANDLER(Z
21362
21401
ZEND_VM_NEXT_OPCODE();
21363
21402
} else if (IS_VAR != IS_CONST && EXPECTED(Z_TYPE_P(array_ptr) == IS_OBJECT)) {
21364
21403
if (!Z_OBJCE_P(array_ptr)->get_iterator) {
21404
+ HashTable *properties;
21365
21405
if (IS_VAR == IS_VAR || IS_VAR == IS_CV) {
21366
21406
if (array_ptr == array_ref) {
21367
21407
ZVAL_NEW_REF(array_ref, array_ref);
@@ -21380,8 +21420,14 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_FE_RESET_RW_SPEC_VAR_HANDLER(Z
21380
21420
}
21381
21421
Z_OBJ_P(array_ptr)->properties = zend_array_dup(Z_OBJ_P(array_ptr)->properties);
21382
21422
}
21383
- Z_FE_ITER_P(EX_VAR(opline->result.var)) = zend_hash_iterator_add(Z_OBJPROP_P(array_ptr), 0);
21384
21423
21424
+ properties = Z_OBJPROP_P(array_ptr);
21425
+ if (zend_hash_num_elements(properties) == 0) {
21426
+ Z_FE_ITER_P(EX_VAR(opline->result.var)) = (uint32_t) -1;
21427
+ ZEND_VM_JMP(OP_JMP_ADDR(opline, opline->op2));
21428
+ }
21429
+
21430
+ Z_FE_ITER_P(EX_VAR(opline->result.var)) = zend_hash_iterator_add(properties, 0);
21385
21431
if (UNEXPECTED(free_op1)) {zval_ptr_dtor_nogc(free_op1);};
21386
21432
ZEND_VM_NEXT_OPCODE_CHECK_EXCEPTION();
21387
21433
} else {
@@ -37792,19 +37838,26 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_FE_RESET_R_SPEC_CV_HANDLER(ZEN
37792
37838
ZEND_VM_NEXT_OPCODE();
37793
37839
} else if (IS_CV != IS_CONST && EXPECTED(Z_TYPE_P(array_ptr) == IS_OBJECT)) {
37794
37840
if (!Z_OBJCE_P(array_ptr)->get_iterator) {
37795
- result = EX_VAR(opline->result.var);
37796
- ZVAL_COPY_VALUE(result, array_ptr);
37797
- if (IS_CV != IS_TMP_VAR) {
37798
- Z_ADDREF_P(array_ptr);
37799
- }
37841
+ HashTable *properties;
37800
37842
if (Z_OBJ_P(array_ptr)->properties
37801
37843
&& UNEXPECTED(GC_REFCOUNT(Z_OBJ_P(array_ptr)->properties) > 1)) {
37802
37844
if (EXPECTED(!(GC_FLAGS(Z_OBJ_P(array_ptr)->properties) & IS_ARRAY_IMMUTABLE))) {
37803
37845
GC_DELREF(Z_OBJ_P(array_ptr)->properties);
37804
37846
}
37805
37847
Z_OBJ_P(array_ptr)->properties = zend_array_dup(Z_OBJ_P(array_ptr)->properties);
37806
37848
}
37807
- Z_FE_ITER_P(EX_VAR(opline->result.var)) = zend_hash_iterator_add(Z_OBJPROP_P(array_ptr), 0);
37849
+
37850
+ properties = Z_OBJPROP_P(array_ptr);
37851
+ if (zend_hash_num_elements(properties) == 0) {
37852
+ goto fe_reset_r_empty;
37853
+ }
37854
+
37855
+ result = EX_VAR(opline->result.var);
37856
+ ZVAL_COPY_VALUE(result, array_ptr);
37857
+ if (IS_CV != IS_TMP_VAR) {
37858
+ Z_ADDREF_P(array_ptr);
37859
+ }
37860
+ Z_FE_ITER_P(result) = zend_hash_iterator_add(properties, 0);
37808
37861
37809
37862
ZEND_VM_NEXT_OPCODE_CHECK_EXCEPTION();
37810
37863
} else {
@@ -37820,6 +37873,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_FE_RESET_R_SPEC_CV_HANDLER(ZEN
37820
37873
}
37821
37874
} else {
37822
37875
zend_error(E_WARNING, "Invalid argument supplied for foreach()");
37876
+ fe_reset_r_empty:
37823
37877
ZVAL_UNDEF(EX_VAR(opline->result.var));
37824
37878
Z_FE_ITER_P(EX_VAR(opline->result.var)) = (uint32_t)-1;
37825
37879
@@ -37870,6 +37924,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_FE_RESET_RW_SPEC_CV_HANDLER(ZE
37870
37924
ZEND_VM_NEXT_OPCODE();
37871
37925
} else if (IS_CV != IS_CONST && EXPECTED(Z_TYPE_P(array_ptr) == IS_OBJECT)) {
37872
37926
if (!Z_OBJCE_P(array_ptr)->get_iterator) {
37927
+ HashTable *properties;
37873
37928
if (IS_CV == IS_VAR || IS_CV == IS_CV) {
37874
37929
if (array_ptr == array_ref) {
37875
37930
ZVAL_NEW_REF(array_ref, array_ref);
@@ -37888,7 +37943,14 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_FE_RESET_RW_SPEC_CV_HANDLER(ZE
37888
37943
}
37889
37944
Z_OBJ_P(array_ptr)->properties = zend_array_dup(Z_OBJ_P(array_ptr)->properties);
37890
37945
}
37891
- Z_FE_ITER_P(EX_VAR(opline->result.var)) = zend_hash_iterator_add(Z_OBJPROP_P(array_ptr), 0);
37946
+
37947
+ properties = Z_OBJPROP_P(array_ptr);
37948
+ if (zend_hash_num_elements(properties) == 0) {
37949
+ Z_FE_ITER_P(EX_VAR(opline->result.var)) = (uint32_t) -1;
37950
+ ZEND_VM_JMP(OP_JMP_ADDR(opline, opline->op2));
37951
+ }
37952
+
37953
+ Z_FE_ITER_P(EX_VAR(opline->result.var)) = zend_hash_iterator_add(properties, 0);
37892
37954
37893
37955
ZEND_VM_NEXT_OPCODE_CHECK_EXCEPTION();
37894
37956
} else {
0 commit comments