diff options
author | Dmitry Stogov <dmitry@zend.com> | 2014-02-10 10:04:30 +0400 |
---|---|---|
committer | Dmitry Stogov <dmitry@zend.com> | 2014-02-10 10:04:30 +0400 |
commit | f4cfaf36e23ca47da3e352e1c60909104c059647 (patch) | |
tree | 0db3e2a323b12c5bbf1a958c857f92eb58c240d1 /Zend/zend_objects.c | |
parent | 89a9acea1f9d821a9805b3857bf4febbba08690d (diff) | |
download | php-git-f4cfaf36e23ca47da3e352e1c60909104c059647.tar.gz |
Use better data structures (incomplete)
Diffstat (limited to 'Zend/zend_objects.c')
-rw-r--r-- | Zend/zend_objects.c | 131 |
1 files changed, 50 insertions, 81 deletions
diff --git a/Zend/zend_objects.c b/Zend/zend_objects.c index da3aab551d..cf7ac3fa6c 100644 --- a/Zend/zend_objects.c +++ b/Zend/zend_objects.c @@ -28,14 +28,20 @@ ZEND_API void zend_object_std_init(zend_object *object, zend_class_entry *ce TSRMLS_DC) { + object->gc.refcount = 1; + object->gc.u.v.type = IS_OBJECT; + object->gc.u.v.buffer = 0; object->ce = ce; object->properties = NULL; - object->properties_table = NULL; object->guards = NULL; + memset(object->properties_table, 0, sizeof(zval) * ce->default_properties_count); + zend_objects_store_put(object); } ZEND_API void zend_object_std_dtor(zend_object *object TSRMLS_DC) { + int i; + if (object->guards) { zend_hash_destroy(object->guards); FREE_HASHTABLE(object->guards); @@ -46,26 +52,19 @@ ZEND_API void zend_object_std_dtor(zend_object *object TSRMLS_DC) if (object->properties_table) { efree(object->properties_table); } - } else if (object->properties_table) { - int i; - - for (i = 0; i < object->ce->default_properties_count; i++) { - if (object->properties_table[i]) { - zval_ptr_dtor(&object->properties_table[i]); - } - } - efree(object->properties_table); + } + for (i = 0; i < object->ce->default_properties_count; i++) { + zval_ptr_dtor(&object->properties_table[i]); } } -ZEND_API void zend_objects_destroy_object(zend_object *object, zend_object_handle handle TSRMLS_DC) +ZEND_API void zend_objects_destroy_object(zend_object *object TSRMLS_DC) { zend_function *destructor = object ? object->ce->destructor : NULL; if (destructor) { - zval *old_exception; - zval *obj; - zend_object_store_bucket *obj_bucket; + zend_object *old_exception; + zval obj; if (destructor->op_array.fn_flags & (ZEND_ACC_PRIVATE|ZEND_ACC_PROTECTED)) { if (destructor->op_array.fn_flags & ZEND_ACC_PRIVATE) { @@ -76,8 +75,8 @@ ZEND_API void zend_objects_destroy_object(zend_object *object, zend_object_handl zend_error(EG(in_execution) ? E_ERROR : E_WARNING, "Call to private %s::__destruct() from context '%s'%s", - ce->name, - EG(scope) ? EG(scope)->name : "", + ce->name->val, + EG(scope) ? EG(scope)->name->val : "", EG(in_execution) ? "" : " during shutdown ignored"); return; } @@ -89,23 +88,16 @@ ZEND_API void zend_objects_destroy_object(zend_object *object, zend_object_handl zend_error(EG(in_execution) ? E_ERROR : E_WARNING, "Call to protected %s::__destruct() from context '%s'%s", - ce->name, - EG(scope) ? EG(scope)->name : "", + ce->name->val, + EG(scope) ? EG(scope)->name->val : "", EG(in_execution) ? "" : " during shutdown ignored"); return; } } } - MAKE_STD_ZVAL(obj); - Z_TYPE_P(obj) = IS_OBJECT; - Z_OBJ_HANDLE_P(obj) = handle; - obj_bucket = &EG(objects_store).object_buckets[handle]; - if (!obj_bucket->bucket.obj.handlers) { - obj_bucket->bucket.obj.handlers = &std_object_handlers; - } - Z_OBJ_HT_P(obj) = obj_bucket->bucket.obj.handlers; - zval_copy_ctor(obj); + ZVAL_OBJ(&obj, object); + Z_ADDREF(obj); /* Make sure that destructors are protected from previously thrown exceptions. * For example, if an exception was thrown in a function and when the function's @@ -113,7 +105,7 @@ ZEND_API void zend_objects_destroy_object(zend_object *object, zend_object_handl */ old_exception = NULL; if (EG(exception)) { - if (Z_OBJ_HANDLE_P(EG(exception)) == handle) { + if (EG(exception) == object) { zend_error(E_ERROR, "Attempt to destruct pending exception"); } else { old_exception = EG(exception); @@ -132,69 +124,52 @@ ZEND_API void zend_objects_destroy_object(zend_object *object, zend_object_handl } } -ZEND_API void zend_objects_free_object_storage(zend_object *object TSRMLS_DC) +ZEND_API void zend_object_free(zend_object *object TSRMLS_DC) { zend_object_std_dtor(object TSRMLS_CC); efree(object); } -ZEND_API zend_object_value zend_objects_new(zend_object **object, zend_class_entry *class_type TSRMLS_DC) +ZEND_API zend_object *zend_objects_new(zend_class_entry *ce TSRMLS_DC) { - zend_object_value retval; - - *object = emalloc(sizeof(zend_object)); - (*object)->ce = class_type; - (*object)->properties = NULL; - (*object)->properties_table = NULL; - (*object)->guards = NULL; - retval.handle = zend_objects_store_put(*object, (zend_objects_store_dtor_t) zend_objects_destroy_object, (zend_objects_free_object_storage_t) zend_objects_free_object_storage, NULL TSRMLS_CC); - retval.handlers = &std_object_handlers; - return retval; -} + zend_object *object = emalloc(sizeof(zend_object) + sizeof(zval) * (ce->default_properties_count - 1)); -ZEND_API zend_object *zend_objects_get_address(const zval *zobject TSRMLS_DC) -{ - return (zend_object *)zend_object_store_get_object(zobject TSRMLS_CC); + zend_object_std_init(object, ce); + object->handlers = &std_object_handlers; + return object; } -ZEND_API void zend_objects_clone_members(zend_object *new_object, zend_object_value new_obj_val, zend_object *old_object, zend_object_handle handle TSRMLS_DC) +ZEND_API void zend_objects_clone_members(zend_object *new_object, zend_object *old_object TSRMLS_DC) { int i; - if (old_object->properties_table) { - if (!new_object->properties_table) { - new_object->properties_table = emalloc(sizeof(zval*) * old_object->ce->default_properties_count); - memset(new_object->properties_table, 0, sizeof(zval*) * old_object->ce->default_properties_count); - } - for (i = 0; i < old_object->ce->default_properties_count; i++) { - if (!new_object->properties) { - if (new_object->properties_table[i]) { - zval_ptr_dtor(&new_object->properties_table[i]); - } - } - if (!old_object->properties) { - new_object->properties_table[i] = old_object->properties_table[i]; - if (new_object->properties_table[i]) { - Z_ADDREF_P(new_object->properties_table[i]); - } - } - } + for (i = 0; i < old_object->ce->default_properties_count; i++) { +//??? if (!new_object->properties) { + zval_ptr_dtor(&new_object->properties_table[i]); +//??? } +//??? if (!old_object->properties) { + ZVAL_COPY(&new_object->properties_table[i], &old_object->properties_table[i]); +//??? } } if (old_object->properties) { if (!new_object->properties) { ALLOC_HASHTABLE(new_object->properties); zend_hash_init(new_object->properties, 0, NULL, ZVAL_PTR_DTOR, 0); } - zend_hash_copy(new_object->properties, old_object->properties, (copy_ctor_func_t) zval_add_ref, (void *) NULL /* Not used anymore */, sizeof(zval *)); + zend_hash_copy(new_object->properties, old_object->properties, zval_add_ref); if (old_object->properties_table) { HashPosition pos; + zval *prop; zend_property_info *prop_info; + for (zend_hash_internal_pointer_reset_ex(&old_object->ce->properties_info, &pos); - zend_hash_get_current_data_ex(&old_object->ce->properties_info, (void**)&prop_info, &pos) == SUCCESS; + (prop_info = zend_hash_get_current_data_ptr_ex(&old_object->ce->properties_info, &pos)) != NULL; zend_hash_move_forward_ex(&old_object->ce->properties_info, &pos)) { if ((prop_info->flags & ZEND_ACC_STATIC) == 0) { - if (zend_hash_quick_find(new_object->properties, prop_info->name, prop_info->name_length+1, prop_info->h, (void**)&new_object->properties_table[prop_info->offset]) == FAILURE) { - new_object->properties_table[prop_info->offset] = NULL; + if ((prop = zend_hash_find_ptr(new_object->properties, prop_info->name)) != NULL) { + ZVAL_COPY(&new_object->properties_table[prop_info->offset], prop); + } else { + ZVAL_UNDEF(&new_object->properties_table[prop_info->offset]); } } } @@ -202,34 +177,28 @@ ZEND_API void zend_objects_clone_members(zend_object *new_object, zend_object_va } if (old_object->ce->clone) { - zval *new_obj; - - MAKE_STD_ZVAL(new_obj); - new_obj->type = IS_OBJECT; - new_obj->value.obj = new_obj_val; - zval_copy_ctor(new_obj); + zval new_obj; + ZVAL_OBJ(&new_obj, new_object); + zval_copy_ctor(&new_obj); zend_call_method_with_0_params(&new_obj, old_object->ce, &old_object->ce->clone, ZEND_CLONE_FUNC_NAME, NULL); - zval_ptr_dtor(&new_obj); } } -ZEND_API zend_object_value zend_objects_clone_obj(zval *zobject TSRMLS_DC) +ZEND_API zend_object *zend_objects_clone_obj(zval *zobject TSRMLS_DC) { - zend_object_value new_obj_val; zend_object *old_object; zend_object *new_object; - zend_object_handle handle = Z_OBJ_HANDLE_P(zobject); /* assume that create isn't overwritten, so when clone depends on the * overwritten one then it must itself be overwritten */ - old_object = zend_objects_get_address(zobject TSRMLS_CC); - new_obj_val = zend_objects_new(&new_object, old_object->ce TSRMLS_CC); + old_object = Z_OBJ_P(zobject); + new_object = zend_objects_new(old_object->ce TSRMLS_CC); - zend_objects_clone_members(new_object, new_obj_val, old_object, handle TSRMLS_CC); + zend_objects_clone_members(new_object, old_object TSRMLS_CC); - return new_obj_val; + return new_object; } /* |