mirror of
https://github.com/php/php-src.git
synced 2025-01-21 03:03:41 +08:00
Conversion related optimizations
This commit is contained in:
parent
85b2bc38e1
commit
ca40664ad6
@ -374,9 +374,8 @@ try_again:
|
|||||||
zval_dtor(op);
|
zval_dtor(op);
|
||||||
|
|
||||||
if (Z_TYPE(dst) == IS_LONG) {
|
if (Z_TYPE(dst) == IS_LONG) {
|
||||||
ZVAL_COPY_VALUE(op, &dst);
|
ZVAL_LONG(op, Z_LVAL(dst));
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
ZVAL_LONG(op, 1);
|
ZVAL_LONG(op, 1);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
@ -434,7 +433,7 @@ try_again:
|
|||||||
zval_dtor(op);
|
zval_dtor(op);
|
||||||
|
|
||||||
if (Z_TYPE(dst) == IS_DOUBLE) {
|
if (Z_TYPE(dst) == IS_DOUBLE) {
|
||||||
ZVAL_COPY_VALUE(op, &dst);
|
ZVAL_DOUBLE(op, Z_DVAL(dst));
|
||||||
} else {
|
} else {
|
||||||
ZVAL_DOUBLE(op, 1.0);
|
ZVAL_DOUBLE(op, 1.0);
|
||||||
}
|
}
|
||||||
@ -505,8 +504,8 @@ try_again:
|
|||||||
convert_object_to_type(op, &dst, _IS_BOOL, convert_to_boolean);
|
convert_object_to_type(op, &dst, _IS_BOOL, convert_to_boolean);
|
||||||
zval_dtor(op);
|
zval_dtor(op);
|
||||||
|
|
||||||
if (Z_TYPE(dst) == IS_FALSE || Z_TYPE(dst) == IS_TRUE) {
|
if (Z_TYPE_INFO(dst) == IS_FALSE || Z_TYPE_INFO(dst) == IS_TRUE) {
|
||||||
ZVAL_COPY_VALUE(op, &dst);
|
Z_TYPE_INFO_P(op) = Z_TYPE_INFO(dst);
|
||||||
} else {
|
} else {
|
||||||
ZVAL_TRUE(op);
|
ZVAL_TRUE(op);
|
||||||
}
|
}
|
||||||
@ -596,12 +595,9 @@ try_again:
|
|||||||
|
|
||||||
static void convert_scalar_to_array(zval *op) /* {{{ */
|
static void convert_scalar_to_array(zval *op) /* {{{ */
|
||||||
{
|
{
|
||||||
zval entry;
|
HashTable *ht = zend_new_array(1);
|
||||||
|
zend_hash_index_add_new(ht, 0, op);
|
||||||
ZVAL_COPY_VALUE(&entry, op);
|
ZVAL_ARR(op, ht);
|
||||||
|
|
||||||
array_init_size(op, 1);
|
|
||||||
zend_hash_index_add_new(Z_ARRVAL_P(op), 0, &entry);
|
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
@ -619,19 +615,13 @@ try_again:
|
|||||||
if (Z_OBJ_HT_P(op)->get_properties) {
|
if (Z_OBJ_HT_P(op)->get_properties) {
|
||||||
HashTable *obj_ht = Z_OBJ_HT_P(op)->get_properties(op);
|
HashTable *obj_ht = Z_OBJ_HT_P(op)->get_properties(op);
|
||||||
if (obj_ht) {
|
if (obj_ht) {
|
||||||
zend_array *arr;
|
|
||||||
|
|
||||||
/* fast copy */
|
/* fast copy */
|
||||||
if (!Z_OBJCE_P(op)->default_properties_count &&
|
obj_ht = zend_proptable_to_symtable(obj_ht,
|
||||||
obj_ht == Z_OBJ_P(op)->properties &&
|
(Z_OBJCE_P(op)->default_properties_count ||
|
||||||
!GC_IS_RECURSIVE(obj_ht) &&
|
Z_OBJ_P(op)->handlers != &std_object_handlers ||
|
||||||
EXPECTED(Z_OBJ_P(op)->handlers == &std_object_handlers)) {
|
GC_IS_RECURSIVE(obj_ht)));
|
||||||
arr = zend_proptable_to_symtable(obj_ht, 0);
|
|
||||||
} else {
|
|
||||||
arr = zend_proptable_to_symtable(obj_ht, 1);
|
|
||||||
}
|
|
||||||
zval_dtor(op);
|
zval_dtor(op);
|
||||||
ZVAL_ARR(op, arr);
|
ZVAL_ARR(op, obj_ht);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -670,14 +660,20 @@ try_again:
|
|||||||
switch (Z_TYPE_P(op)) {
|
switch (Z_TYPE_P(op)) {
|
||||||
case IS_ARRAY:
|
case IS_ARRAY:
|
||||||
{
|
{
|
||||||
HashTable *ht = Z_ARR_P(op);
|
HashTable *ht = zend_symtable_to_proptable(Z_ARR_P(op));
|
||||||
ht = zend_symtable_to_proptable(ht);
|
zend_object *obj;
|
||||||
|
|
||||||
if (GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) {
|
if (GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) {
|
||||||
/* TODO: try not to duplicate immutable arrays as well ??? */
|
/* TODO: try not to duplicate immutable arrays as well ??? */
|
||||||
ht = zend_array_dup(ht);
|
ht = zend_array_dup(ht);
|
||||||
|
} else if (ht != Z_ARR_P(op)) {
|
||||||
|
zval_dtor(op);
|
||||||
|
} else {
|
||||||
|
GC_DELREF(ht);
|
||||||
}
|
}
|
||||||
zval_dtor(op);
|
obj = zend_objects_new(zend_standard_class_def);
|
||||||
object_and_properties_init(op, zend_standard_class_def, ht);
|
obj->properties = ht;
|
||||||
|
ZVAL_OBJ(op, obj);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case IS_OBJECT:
|
case IS_OBJECT:
|
||||||
|
@ -437,7 +437,13 @@ ZEND_API void ZEND_FASTCALL zend_locale_sprintf_double(zval *op ZEND_FILE_LINE_D
|
|||||||
convert_to_explicit_type(pzv, str_type); \
|
convert_to_explicit_type(pzv, str_type); \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define convert_to_boolean_ex(pzv) convert_to_ex_master(pzv, boolean, _IS_BOOL)
|
#define convert_to_boolean_ex(pzv) do { \
|
||||||
|
if (Z_TYPE_INFO_P(pzv) > IS_TRUE) { \
|
||||||
|
convert_to_boolean(pzv); \
|
||||||
|
} else if (Z_TYPE_INFO_P(pzv) < IS_FALSE) { \
|
||||||
|
ZVAL_FALSE(pzv); \
|
||||||
|
} \
|
||||||
|
} while (0)
|
||||||
#define convert_to_long_ex(pzv) convert_to_ex_master(pzv, long, IS_LONG)
|
#define convert_to_long_ex(pzv) convert_to_ex_master(pzv, long, IS_LONG)
|
||||||
#define convert_to_double_ex(pzv) convert_to_ex_master(pzv, double, IS_DOUBLE)
|
#define convert_to_double_ex(pzv) convert_to_ex_master(pzv, double, IS_DOUBLE)
|
||||||
#define convert_to_string_ex(pzv) convert_to_ex_master(pzv, string, IS_STRING)
|
#define convert_to_string_ex(pzv) convert_to_ex_master(pzv, string, IS_STRING)
|
||||||
|
Loading…
Reference in New Issue
Block a user