Skip to content

Commit

Permalink
another test
Browse files Browse the repository at this point in the history
  • Loading branch information
nielsdos committed Oct 18, 2023
1 parent 77581cc commit 64fb530
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 21 deletions.
32 changes: 18 additions & 14 deletions Zend/zend_API.c
Original file line number Diff line number Diff line change
Expand Up @@ -1608,26 +1608,30 @@ static zend_always_inline void _object_properties_init(zend_object *object, zend
zval *src = CE_DEFAULT_PROPERTIES_TABLE(class_type);
zval *dst = object->properties_table;

if (!(class_type->ce_flags & ZEND_ACC_HAS_RC_PROPS)) {
if (false && !(class_type->ce_flags & ZEND_ACC_HAS_RC_PROPS)) {//TODO: disabled; also actually this may replace the internal class thing?
// printf("fast path %s\n", class_type->name->val);
// memcpy(dst, src, sizeof(zval) * class_type->default_properties_count);
zval *end = src + class_type->default_properties_count;
do {
ZVAL_COPY_VALUE_PROP(dst, src);
src++;
dst++;
} while (src != end);
memcpy(dst, src, sizeof(zval) * class_type->default_properties_count);
// zval *end = src + class_type->default_properties_count;
// do {
// ZVAL_COPY_VALUE_PROP(dst, src);
// src++;
// dst++;
// } while (src != end);
} else {
// printf("slow path %s\n", class_type->name->val);
zval *end = src + class_type->default_properties_count;
// zval *end = src + class_type->default_properties_count;

if (UNEXPECTED(class_type->type == ZEND_INTERNAL_CLASS)) {
do {
ZVAL_COPY_OR_DUP_PROP(dst, src);
src++;
dst++;
} while (src != end);
// do {
// ZVAL_COPY_OR_DUP_PROP(dst, src);
// src++;
// dst++;
// } while (src != end);
// TODO: assertion?
/* zend_declare_typed_property() disallows refcounted default property values in internal classes */
memcpy(dst, src, sizeof(zval) * class_type->default_properties_count);
} else {
zval *end = src + class_type->default_properties_count;
do {
ZVAL_COPY_PROP(dst, src);
src++;
Expand Down
22 changes: 22 additions & 0 deletions Zend/zend_operators.c
Original file line number Diff line number Diff line change
Expand Up @@ -2372,6 +2372,28 @@ static int hash_zval_identical_function(zval *z1, zval *z2) /* {{{ */
}
/* }}} */

ZEND_API bool ZEND_FASTCALL zend_is_identical2(const zval *op1, const zval *op2)
{
switch (Z_TYPE_P(op1)) {
case IS_LONG:
return (Z_LVAL_P(op1) == Z_LVAL_P(op2));
case IS_RESOURCE:
return (Z_RES_P(op1) == Z_RES_P(op2));
case IS_DOUBLE:
return (Z_DVAL_P(op1) == Z_DVAL_P(op2));
case IS_STRING:
return zend_string_equals(Z_STR_P(op1), Z_STR_P(op2));
case IS_ARRAY:
return (Z_ARRVAL_P(op1) == Z_ARRVAL_P(op2) ||
zend_hash_compare(Z_ARRVAL_P(op1), Z_ARRVAL_P(op2), (compare_func_t) hash_zval_identical_function, 1) == 0);
case IS_OBJECT:
return (Z_OBJ_P(op1) == Z_OBJ_P(op2));
default:
return 0;
}
}

// TODO: use zend_is_identical2 ?
ZEND_API bool ZEND_FASTCALL zend_is_identical(const zval *op1, const zval *op2) /* {{{ */
{
if (Z_TYPE_P(op1) != Z_TYPE_P(op2)) {
Expand Down
5 changes: 3 additions & 2 deletions Zend/zend_operators.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ ZEND_API zend_result ZEND_FASTCALL shift_right_function(zval *result, zval *op1,
ZEND_API zend_result ZEND_FASTCALL concat_function(zval *result, zval *op1, zval *op2);

ZEND_API bool ZEND_FASTCALL zend_is_identical(const zval *op1, const zval *op2);
ZEND_API bool ZEND_FASTCALL zend_is_identical2(const zval *op1, const zval *op2);

ZEND_API zend_result ZEND_FASTCALL is_equal_function(zval *result, zval *op1, zval *op2);
ZEND_API zend_result ZEND_FASTCALL is_identical_function(zval *result, zval *op1, zval *op2);
Expand Down Expand Up @@ -856,7 +857,7 @@ static zend_always_inline bool fast_is_identical_function(zval *op1, zval *op2)
} else if (Z_TYPE_P(op1) <= IS_TRUE) {
return 1;
}
return zend_is_identical(op1, op2);
return zend_is_identical2(op1, op2);
}

static zend_always_inline bool fast_is_not_identical_function(zval *op1, zval *op2)
Expand All @@ -866,7 +867,7 @@ static zend_always_inline bool fast_is_not_identical_function(zval *op1, zval *o
} else if (Z_TYPE_P(op1) <= IS_TRUE) {
return 0;
}
return !zend_is_identical(op1, op2);
return !zend_is_identical2(op1, op2);
}

/* buf points to the END of the buffer */
Expand Down
10 changes: 5 additions & 5 deletions ext/standard/array.c
Original file line number Diff line number Diff line change
Expand Up @@ -6470,14 +6470,14 @@ PHP_FUNCTION(array_map)
array_init_size(return_value, maxlen);
zend_hash_real_init(Z_ARRVAL_P(return_value), HT_IS_PACKED(Z_ARRVAL(arrays[0])));

ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL(arrays[0]), num_key, str_key, zv) {
fci.retval = &result;
fci.param_count = 1;
fci.params = &arg;
fci.retval = &result;
fci.param_count = 1;
fci.params = &arg;

ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL(arrays[0]), num_key, str_key, zv) {
ZVAL_COPY(&arg, zv);
ret = zend_call_function(&fci, &fci_cache);
i_zval_ptr_dtor(&arg);
Z_TRY_DELREF(arg); /* hash table still holds a reference, no dtor check is necessary */
if (ret != SUCCESS || Z_TYPE(result) == IS_UNDEF) {
zend_array_destroy(Z_ARR_P(return_value));
RETURN_NULL();
Expand Down

0 comments on commit 64fb530

Please sign in to comment.