1
0
Fork 0

use vector for objects/object_handles

git-svn-id: svn://svn.lighttpd.net/xcache/trunk@1567 c26eb9a1-5813-0410-bd6c-c2e55f420ca7
master
Xuefer 9 years ago
parent 30d56bf2d7
commit 07183575ef

@ -2827,7 +2827,7 @@ static void xc_holds_init(TSRMLS_D) /* {{{ */
XG(php_holds_size) = xc_php_hcache.size;
XG(php_holds) = calloc(XG(php_holds_size), sizeof(xc_vector_t));
for (i = 0; i < xc_php_hcache.size; i ++) {
xc_vector_pinit(xc_entry_php_t *, &XG(php_holds[i]));
xc_vector_init_persistent(xc_entry_php_t *, &XG(php_holds[i]));
}
}
@ -2835,7 +2835,7 @@ static void xc_holds_init(TSRMLS_D) /* {{{ */
XG(var_holds_size) = xc_var_hcache.size;
XG(var_holds) = calloc(XG(var_holds_size), sizeof(xc_vector_t));
for (i = 0; i < xc_var_hcache.size; i ++) {
xc_vector_pinit(xc_entry_php_t *, &XG(var_holds[i]));
xc_vector_init_persistent(xc_entry_php_t *, &XG(var_holds[i]));
}
}
}

@ -135,10 +135,11 @@ EXPORTED_FUNCTION(`zval *xc_processor_restore_var(zval *dst, const xc_entry_var_
#ifdef ZEND_ENGINE_2
if (src->objects_count) {
zend_uint i;
processor.object_handles = emalloc(sizeof(*processor.object_handles) * src->objects_count);
xc_vector_init(zend_object_handle, &processor.object_handles);
xc_vector_reserve(&processor.object_handles, src->objects_count);
for (i = 0; i < src->objects_count; ++i) {
zend_object *object = emalloc(sizeof(*object));
processor.object_handles[i] = 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);
xc_vector_data(zend_object_handle, &processor.object_handles)[i] = 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);
xc_restore_zend_object(&processor, object, &src->objects[i] TSRMLS_CC);
}
}
@ -152,9 +153,9 @@ EXPORTED_FUNCTION(`zval *xc_processor_restore_var(zval *dst, const xc_entry_var_
if (src->objects_count) {
zend_uint i;
for (i = 0; i < src->objects_count; ++i) {
zend_objects_store_del_ref_by_handle(processor.object_handles[i] TSRMLS_CC);
zend_objects_store_del_ref_by_handle(xc_vector_data(zend_object_handle, &processor.object_handles)[i] TSRMLS_CC);
}
efree(processor.object_handles);
xc_vector_destroy(&processor.object_handles);
}
#endif

@ -1421,10 +1421,10 @@ DEF_STRUCT_P_FUNC(`xc_entry_var_t', , `dnl {{{
IFCALC(`
dnl objects = collect_from(value);
pushdef(`src', `vsrc')
SRC(objects_count) = xc_vector_size(&processor->objects);
SRC(objects) = xc_vector_detach(zend_object, &processor->objects);
SRC(objects_count) = xc_vector_size(&processor->object_handles);
SRC(objects) = xc_vector_detach(zend_object, &processor->object_handles);
popdef(`src')
xc_vector_destroy(&processor->objects);
xc_vector_destroy(&processor->object_handles);
')
dnl must be after calc .value
PROCESS(zend_uint, objects_count)
@ -1442,7 +1442,7 @@ DEF_STRUCT_P_FUNC(`xc_entry_var_t', , `dnl {{{
dnl classe_
IFCALC(`
dnl class_names = collect_from(objects);
dnl class_names = collect_from(object_handles);
pushdef(`src', `vsrc')
SRC(class_names_count) = xc_vector_size(&processor->class_names);
SRC(class_names) = xc_vector_detach(xc_constant_string_t, &processor->class_names);

@ -1,8 +1,7 @@
/* {{{ var object helpers */
#ifdef ZEND_ENGINE_2
xc_vector_t objects; /* in calc only */
xc_vector_t object_handles; /* in calc/restore only */
HashTable handle_to_index; /* in calc/store only */
zend_object_handle *object_handles; /* in restore only */
#endif
const xc_entry_var_t *entry_var_src; /* in restore */

@ -3,15 +3,15 @@ static void xc_var_collect_object(xc_processor_t *processor, zend_object_handle
{
size_t next_index;
if (!xc_vector_initialized(&processor->objects)) {
xc_vector_init(zend_object, &processor->objects);
if (!xc_vector_initialized(&processor->object_handles)) {
xc_vector_init(zend_object, &processor->object_handles);
zend_hash_init(&processor->handle_to_index, 0, NULL, NULL, 0);
}
next_index = xc_vector_size(&processor->objects);
next_index = xc_vector_size(&processor->object_handles);
if (_zend_hash_index_update_or_next_insert(&processor->handle_to_index, handle, (void *) &next_index, sizeof(next_index), NULL, HASH_ADD ZEND_FILE_LINE_CC) == SUCCESS) {
zend_object *object = zend_object_store_get_object_by_handle(handle TSRMLS_CC);
xc_vector_push_back(&processor->objects, object);
xc_vector_push_back(&processor->object_handles, object);
}
}
/* }}} */
@ -20,7 +20,7 @@ static size_t xc_var_store_handle(xc_processor_t *processor, zend_object_handle
size_t *index;
if (zend_hash_index_find(&processor->handle_to_index, handle, (void **) &index) != SUCCESS) {
php_error_docref(NULL TSRMLS_CC, E_CORE_ERROR, "Internal error: handle %d not found in objects", handle);
php_error_docref(NULL TSRMLS_CC, E_CORE_ERROR, "Internal error: handle %d not found on store", handle);
return (size_t) -1;
}
@ -29,7 +29,7 @@ static size_t xc_var_store_handle(xc_processor_t *processor, zend_object_handle
/* }}} */
static zend_object_handle xc_var_restore_handle(xc_processor_t *processor, size_t index TSRMLS_DC) /* {{{ */
{
zend_object_handle handle = processor->object_handles[index];
zend_object_handle handle = xc_vector_data(zend_object_handle, &processor->object_handles)[index];
zend_objects_store_add_ref_by_handle(handle TSRMLS_CC);
return handle;
}

@ -35,7 +35,7 @@ typedef struct {
} while (0)
#define xc_vector_init(type, vector) xc_vector_init_ex(type, vector, NULL, 0, 0)
#define xc_vector_pinit(type, vector) xc_vector_init_ex(type, vector, NULL, 0, 1)
#define xc_vector_init_persistent(type, vector) xc_vector_init_ex(type, vector, NULL, 0, 1)
static inline void xc_vector_destroy_impl(xc_vector_t *vector TSRMLS_DC)
{
@ -67,17 +67,37 @@ static inline xc_vector_t *xc_vector_check_type_(xc_vector_t *vector, size_t dat
#define xc_vector_data(type, vector) ((type *) xc_vector_check_type_(vector, sizeof(type))->data_)
static void xc_vector_reserve_impl(xc_vector_t *vector, size_t capacity TSRMLS_DC)
{
assert(capacity);
if (!vector->capacity_) {
vector->capacity_ = 8;
}
while (vector->capacity_ <= capacity) {
vector->capacity_ <<= 1;
}
vector->data_ = perealloc(vector->data_, vector->data_size_ * vector->capacity_, vector->persistent_);
}
#define xc_vector_reserve(vector, capacity) xc_vector_reserve_impl(vector, capacity TSRMLS_CC)
static void xc_vector_resize_impl(xc_vector_t *vector, size_t size TSRMLS_DC)
{
assert(size);
xc_vector_reserve(vector, size);
vector->size_ = size;
}
#define xc_vector_resize(vector, size) xc_vector_resize_impl(vector, size TSRMLS_CC)
static inline void xc_vector_check_reserve_(xc_vector_t *vector TSRMLS_DC)
{
if (vector->size_ == vector->capacity_) {
if (vector->capacity_) {
vector->capacity_ <<= 1;
vector->data_ = perealloc(vector->data_, vector->data_size_ * vector->capacity_, vector->persistent_);
}
else {
vector->capacity_ = 8;
vector->data_ = pemalloc(vector->data_size_ * vector->capacity_, vector->persistent_);
}
vector->data_ = perealloc(vector->data_, vector->data_size_ * vector->capacity_, vector->persistent_);
}
}

Loading…
Cancel
Save