Skip to content

Commit 7d6a7e7

Browse files
committed
Use array_set_zval_key() in zend_ast_add_array_element()
This reimplemented basically the same logic.
1 parent 65428d8 commit 7d6a7e7

File tree

1 file changed

+13
-33
lines changed

1 file changed

+13
-33
lines changed

Zend/zend_ast.c

+13-33
Original file line numberDiff line numberDiff line change
@@ -436,41 +436,21 @@ ZEND_API zend_ast * ZEND_FASTCALL zend_ast_list_add(zend_ast *ast, zend_ast *op)
436436

437437
static zend_result zend_ast_add_array_element(zval *result, zval *offset, zval *expr)
438438
{
439-
switch (Z_TYPE_P(offset)) {
440-
case IS_UNDEF:
441-
if (!zend_hash_next_index_insert(Z_ARRVAL_P(result), expr)) {
442-
zend_throw_error(NULL,
443-
"Cannot add element to the array as the next element is already occupied");
444-
return FAILURE;
445-
}
446-
break;
447-
case IS_STRING:
448-
zend_symtable_update(Z_ARRVAL_P(result), Z_STR_P(offset), expr);
449-
zval_ptr_dtor_str(offset);
450-
break;
451-
case IS_NULL:
452-
zend_symtable_update(Z_ARRVAL_P(result), ZSTR_EMPTY_ALLOC(), expr);
453-
break;
454-
case IS_LONG:
455-
zend_hash_index_update(Z_ARRVAL_P(result), Z_LVAL_P(offset), expr);
456-
break;
457-
case IS_FALSE:
458-
zend_hash_index_update(Z_ARRVAL_P(result), 0, expr);
459-
break;
460-
case IS_TRUE:
461-
zend_hash_index_update(Z_ARRVAL_P(result), 1, expr);
462-
break;
463-
case IS_DOUBLE:
464-
zend_hash_index_update(Z_ARRVAL_P(result), zend_dval_to_lval_safe(Z_DVAL_P(offset)), expr);
465-
break;
466-
case IS_RESOURCE:
467-
zend_error(E_WARNING, "Resource ID#%d used as offset, casting to integer (%d)", Z_RES_HANDLE_P(offset), Z_RES_HANDLE_P(offset));
468-
zend_hash_index_update(Z_ARRVAL_P(result), Z_RES_HANDLE_P(offset), expr);
469-
break;
470-
default:
471-
zend_type_error("Illegal offset type");
439+
if (Z_TYPE_P(offset) == IS_UNDEF) {
440+
if (!zend_hash_next_index_insert(Z_ARRVAL_P(result), expr)) {
441+
zend_throw_error(NULL,
442+
"Cannot add element to the array as the next element is already occupied");
472443
return FAILURE;
444+
}
445+
return SUCCESS;
473446
}
447+
448+
if (array_set_zval_key(Z_ARRVAL_P(result), offset, expr) == FAILURE) {
449+
return FAILURE;
450+
}
451+
452+
zval_ptr_dtor_nogc(offset);
453+
zval_ptr_dtor_nogc(expr);
474454
return SUCCESS;
475455
}
476456

0 commit comments

Comments
 (0)