mirror of
https://github.com/php/php-src.git
synced 2024-11-23 18:04:36 +08:00
- Optimize class instanciation
- Fix constant instanciation for array elements inside objects
This commit is contained in:
parent
5cc10ecec2
commit
6358c6631b
@ -160,6 +160,7 @@ struct _zend_class_entry {
|
||||
uint name_length;
|
||||
struct _zend_class_entry *parent;
|
||||
int *refcount;
|
||||
zend_bool constants_updated;
|
||||
|
||||
HashTable function_table;
|
||||
HashTable default_properties;
|
||||
|
@ -199,21 +199,17 @@ ZEND_API inline int array_init(zval *arg)
|
||||
}
|
||||
|
||||
|
||||
static void zval_update_const_and_ref(zval **p)
|
||||
{
|
||||
zval_update_constant(*p);
|
||||
zval_add_ref(p);
|
||||
}
|
||||
|
||||
|
||||
|
||||
ZEND_API inline int object_init_ex(zval *arg, zend_class_entry *class_type)
|
||||
{
|
||||
zval *tmp;
|
||||
|
||||
if (!class_type->constants_updated) {
|
||||
zend_hash_apply(&class_type->default_properties, (int (*)(void *)) zval_update_constant);
|
||||
class_type->constants_updated = 1;
|
||||
}
|
||||
arg->value.obj.properties = (HashTable *) emalloc(sizeof(HashTable));
|
||||
zend_hash_init(arg->value.obj.properties, 0, NULL, PVAL_PTR_DTOR, 0);
|
||||
zend_hash_copy(arg->value.obj.properties, &class_type->default_properties, (void (*)(void *)) zval_update_const_and_ref, (void *) &tmp, sizeof(zval *));
|
||||
zend_hash_copy(arg->value.obj.properties, &class_type->default_properties, (void (*)(void *)) zval_add_ref, (void *) &tmp, sizeof(zval *));
|
||||
arg->type = IS_OBJECT;
|
||||
arg->value.obj.ce = class_type;
|
||||
return SUCCESS;
|
||||
|
@ -1384,6 +1384,7 @@ void do_begin_class_declaration(znode *class_name, znode *parent_class_name CLS_
|
||||
CG(class_entry).name_length = class_name->u.constant.value.str.len;
|
||||
CG(class_entry).refcount = (int *) emalloc(sizeof(int));
|
||||
*CG(class_entry).refcount = 1;
|
||||
CG(class_entry).constants_updated = 0;
|
||||
|
||||
zend_str_tolower(CG(class_entry).name, CG(class_entry).name_length);
|
||||
|
||||
|
@ -49,7 +49,7 @@ ZEND_API int zend_is_true(zval *op);
|
||||
ZEND_API inline void safe_free_zval_ptr(zval *p);
|
||||
ZEND_API void zend_eval_string(char *str, zval *retval CLS_DC ELS_DC);
|
||||
ZEND_API inline int i_zend_is_true(zval *op);
|
||||
ZEND_API void zval_update_constant(zval *p);
|
||||
ZEND_API int zval_update_constant(zval **pp);
|
||||
ZEND_API inline void zend_assign_to_variable_reference(znode *result, zval **variable_ptr_ptr, zval **value_ptr_ptr, temp_variable *Ts ELS_DC);
|
||||
|
||||
/* dedicated Zend executor functions - do not use! */
|
||||
|
@ -260,8 +260,10 @@ ZEND_API int zend_is_true(zval *op)
|
||||
}
|
||||
|
||||
|
||||
ZEND_API void zval_update_constant(zval *p)
|
||||
ZEND_API int zval_update_constant(zval **pp)
|
||||
{
|
||||
zval *p = *pp;
|
||||
|
||||
if (p->type == IS_CONSTANT) {
|
||||
zval c;
|
||||
int refcount = p->refcount;
|
||||
@ -277,7 +279,10 @@ ZEND_API void zval_update_constant(zval *p)
|
||||
}
|
||||
INIT_PZVAL(p);
|
||||
p->refcount = refcount;
|
||||
} else if (p->type == IS_ARRAY) {
|
||||
zend_hash_apply(p->value.ht, (int (*)(void *)) zval_update_constant);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user