Skip to content

Commit fc33001

Browse files
Avoid addref/delref where possible
1 parent 34132a7 commit fc33001

File tree

2 files changed

+41
-129
lines changed

2 files changed

+41
-129
lines changed

Zend/zend_execute.c

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2631,9 +2631,7 @@ static zend_never_inline uint8_t slow_index_convert(HashTable *ht, const zval *d
26312631
case IS_NULL:
26322632
/* The array may be destroyed while throwing the notice.
26332633
* Temporarily increase the refcount to detect this situation. */
2634-
if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE)) {
2635-
GC_ADDREF(ht);
2636-
}
2634+
GC_TRY_ADDREF(ht);
26372635

26382636
zend_error(E_DEPRECATED, "Using null as an array offset is deprecated, use an empty string instead");
26392637

@@ -2718,9 +2716,7 @@ static zend_never_inline uint8_t slow_index_convert_w(HashTable *ht, const zval
27182716
case IS_NULL:
27192717
/* The array may be destroyed while throwing the notice.
27202718
* Temporarily increase the refcount to detect this situation. */
2721-
if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE)) {
2722-
GC_ADDREF(ht);
2723-
}
2719+
GC_TRY_ADDREF(ht);
27242720

27252721
zend_error(E_DEPRECATED, "Using null as an array offset is deprecated, use an empty string instead");
27262722

@@ -3226,9 +3222,7 @@ static zend_never_inline zval* ZEND_FASTCALL zend_find_array_dim_slow(HashTable
32263222
null_undef_idx:
32273223
/* The array may be destroyed while throwing the notice.
32283224
* Temporarily increase the refcount to detect this situation. */
3229-
if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE)) {
3230-
GC_ADDREF(ht);
3231-
}
3225+
GC_TRY_ADDREF(ht);
32323226

32333227
zend_error(E_DEPRECATED, "Using null as an array offset is deprecated, use an empty string instead");
32343228

ext/opcache/jit/zend_jit_helpers.c

Lines changed: 38 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -500,33 +500,17 @@ static void ZEND_FASTCALL zend_jit_fetch_dim_r_helper(zend_array *ht, zval *dim,
500500
}
501501
ZEND_FALLTHROUGH;
502502
case IS_NULL:
503-
/* The array may be destroyed while throwing the notice.
504-
* Temporarily increase the refcount to detect this situation. */
505-
if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE)) {
506-
GC_ADDREF(ht);
503+
retval = zend_hash_find(ht, ZSTR_EMPTY_ALLOC());
504+
if (!retval) {
505+
zend_error(E_WARNING, "Undefined array key \"\"");
506+
ZVAL_NULL(result);
507+
} else {
508+
ZVAL_COPY_DEREF(result, retval);
507509
}
508-
execute_data = EG(current_execute_data);
509-
opline = EX(opline);
510+
510511
zend_error(E_DEPRECATED, "Using null as an array offset is deprecated, use an empty string instead");
511-
if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && !GC_DELREF(ht)) {
512-
zend_array_destroy(ht);
513-
if (opline->result_type & (IS_VAR | IS_TMP_VAR)) {
514-
if (EG(exception)) {
515-
ZVAL_UNDEF(EX_VAR(opline->result.var));
516-
} else {
517-
ZVAL_NULL(EX_VAR(opline->result.var));
518-
}
519-
}
520-
return;
521-
}
522-
if (EG(exception)) {
523-
if (opline->result_type & (IS_VAR | IS_TMP_VAR)) {
524-
ZVAL_UNDEF(EX_VAR(opline->result.var));
525-
}
526-
return;
527-
}
528-
offset_key = ZSTR_EMPTY_ALLOC();
529-
goto str_index;
512+
513+
return;
530514
case IS_DOUBLE:
531515
hval = zend_dval_to_lval(Z_DVAL_P(dim));
532516
if (!zend_is_long_compatible(Z_DVAL_P(dim), hval)) {
@@ -667,33 +651,17 @@ static void ZEND_FASTCALL zend_jit_fetch_dim_is_helper(zend_array *ht, zval *dim
667651
}
668652
ZEND_FALLTHROUGH;
669653
case IS_NULL:
670-
/* The array may be destroyed while throwing the notice.
671-
* Temporarily increase the refcount to detect this situation. */
672-
if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE)) {
673-
GC_ADDREF(ht);
654+
retval = zend_hash_find(ht, ZSTR_EMPTY_ALLOC());
655+
if (!retval) {
656+
zend_error(E_WARNING, "Undefined array key \"\"");
657+
ZVAL_NULL(result);
658+
} else {
659+
ZVAL_COPY_DEREF(result, retval);
674660
}
675-
execute_data = EG(current_execute_data);
676-
opline = EX(opline);
661+
677662
zend_error(E_DEPRECATED, "Using null as an array offset is deprecated, use an empty string instead");
678-
if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && !GC_DELREF(ht)) {
679-
zend_array_destroy(ht);
680-
if (opline->result_type & (IS_VAR | IS_TMP_VAR)) {
681-
if (EG(exception)) {
682-
ZVAL_UNDEF(EX_VAR(opline->result.var));
683-
} else {
684-
ZVAL_NULL(EX_VAR(opline->result.var));
685-
}
686-
}
687-
return;
688-
}
689-
if (EG(exception)) {
690-
if (opline->result_type & (IS_VAR | IS_TMP_VAR)) {
691-
ZVAL_UNDEF(EX_VAR(opline->result.var));
692-
}
693-
return;
694-
}
695-
offset_key = ZSTR_EMPTY_ALLOC();
696-
goto str_index;
663+
664+
return;
697665
case IS_DOUBLE:
698666
hval = zend_dval_to_lval(Z_DVAL_P(dim));
699667
if (!zend_is_long_compatible(Z_DVAL_P(dim), hval)) {
@@ -820,21 +788,16 @@ static int ZEND_FASTCALL zend_jit_fetch_dim_isset_helper(zend_array *ht, zval *d
820788
}
821789
ZEND_FALLTHROUGH;
822790
case IS_NULL:
823-
/* The array may be destroyed while throwing the notice.
824-
* Temporarily increase the refcount to detect this situation. */
825-
if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE)) {
826-
GC_ADDREF(ht);
827-
}
828-
zend_error(E_DEPRECATED, "Using null as an array offset is deprecated, use an empty string instead");
829-
if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && !GC_DELREF(ht)) {
830-
zend_array_destroy(ht);
831-
return 0;
832-
}
833-
if (EG(exception)) {
791+
retval = zend_hash_find(ht, ZSTR_EMPTY_ALLOC());
792+
if (!retval) {
793+
zend_error(E_WARNING, "Undefined array key \"\"");
794+
zend_error(E_DEPRECATED, "Using null as an array offset is deprecated, use an empty string instead");
834795
return 0;
835796
}
836-
offset_key = ZSTR_EMPTY_ALLOC();
837-
goto str_index;
797+
798+
zend_error(E_DEPRECATED, "Using null as an array offset is deprecated, use an empty string instead");
799+
800+
return Z_TYPE_P(retval) > IS_NULL;
838801
case IS_DOUBLE:
839802
hval = zend_dval_to_lval(Z_DVAL_P(dim));
840803
if (!zend_is_long_compatible(Z_DVAL_P(dim), hval)) {
@@ -941,35 +904,14 @@ static zval* ZEND_FASTCALL zend_jit_fetch_dim_rw_helper(zend_array *ht, zval *di
941904
}
942905
ZEND_FALLTHROUGH;
943906
case IS_NULL:
944-
/* The array may be destroyed while throwing the notice.
945-
* Temporarily increase the refcount to detect this situation. */
946-
if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE)) {
947-
GC_ADDREF(ht);
948-
}
949-
execute_data = EG(current_execute_data);
950-
opline = EX(opline);
951-
zend_error(E_DEPRECATED, "Using null as an array offset is deprecated, use an empty string instead");
952-
if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && GC_DELREF(ht) != 1) {
953-
if (!GC_REFCOUNT(ht)) {
954-
zend_array_destroy(ht);
955-
}
956-
if (opline->result_type & (IS_VAR | IS_TMP_VAR)) {
957-
if (EG(exception)) {
958-
ZVAL_UNDEF(EX_VAR(opline->result.var));
959-
} else {
960-
ZVAL_NULL(EX_VAR(opline->result.var));
961-
}
962-
}
963-
return NULL;
964-
}
965-
if (EG(exception)) {
966-
if (opline->result_type & (IS_VAR | IS_TMP_VAR)) {
967-
ZVAL_UNDEF(EX_VAR(opline->result.var));
968-
}
907+
retval = zend_hash_find(ht, ZSTR_EMPTY_ALLOC());
908+
if (!retval) {
909+
zend_error(E_WARNING, "Undefined array key \"\"");
910+
zend_error(E_DEPRECATED, "Using null as an array offset is deprecated, use an empty string instead");
969911
return NULL;
970912
}
971-
offset_key = ZSTR_EMPTY_ALLOC();
972-
goto str_index;
913+
914+
return retval;
973915
case IS_DOUBLE:
974916
hval = zend_dval_to_lval(Z_DVAL_P(dim));
975917
if (!zend_is_long_compatible(Z_DVAL_P(dim), hval)) {
@@ -1101,39 +1043,15 @@ static zval* ZEND_FASTCALL zend_jit_fetch_dim_w_helper(zend_array *ht, zval *dim
11011043
}
11021044
ZEND_FALLTHROUGH;
11031045
case IS_NULL:
1104-
/* The array may be destroyed while throwing the notice.
1105-
* Temporarily increase the refcount to detect this situation. */
1106-
if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE)) {
1107-
GC_ADDREF(ht);
1108-
}
1109-
execute_data = EG(current_execute_data);
1110-
opline = EX(opline);
1046+
retval = zend_hash_find(ht, ZSTR_EMPTY_ALLOC());
11111047
zend_error(E_DEPRECATED, "Using null as an array offset is deprecated, use an empty string instead");
1112-
if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && GC_DELREF(ht) != 1) {
1113-
if (!GC_REFCOUNT(ht)) {
1114-
zend_array_destroy(ht);
1115-
}
1116-
if (opline->result_type & (IS_VAR | IS_TMP_VAR)) {
1117-
if (EG(exception)) {
1118-
ZVAL_UNDEF(EX_VAR(opline->result.var));
1119-
} else {
1120-
ZVAL_NULL(EX_VAR(opline->result.var));
1121-
}
1122-
}
1123-
if (opline->opcode == ZEND_ASSIGN_DIM
1124-
&& ((opline+1)->op1_type & (IS_VAR | IS_TMP_VAR))) {
1125-
zval_ptr_dtor_nogc(EX_VAR((opline+1)->op1.var));
1126-
}
1127-
return NULL;
1128-
}
1129-
if (EG(exception)) {
1130-
if (opline->result_type & (IS_VAR | IS_TMP_VAR)) {
1131-
ZVAL_UNDEF(EX_VAR(opline->result.var));
1132-
}
1048+
1049+
if (!retval) {
1050+
zend_error(E_WARNING, "Undefined array key \"\"");
11331051
return NULL;
11341052
}
1135-
offset_key = ZSTR_EMPTY_ALLOC();
1136-
goto str_index;
1053+
1054+
return retval;
11371055
case IS_DOUBLE:
11381056
hval = zend_dval_to_lval(Z_DVAL_P(dim));
11391057
if (!zend_is_long_compatible(Z_DVAL_P(dim), hval)) {

0 commit comments

Comments
 (0)