Changeset 1568 in svn


Ignore:
Timestamp:
2014-11-11T18:27:44Z (4 years ago)
Author:
Xuefer
Message:

handle nested object caching

Location:
trunk/processor
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/processor/foot.m4

    r1567 r1568  
    135135#ifdef ZEND_ENGINE_2
    136136    if (src->objects_count) {
    137         zend_uint i;
    138         xc_vector_init(zend_object_handle, &processor.object_handles);
    139         xc_vector_reserve(&processor.object_handles, src->objects_count);
    140         for (i = 0; i < src->objects_count; ++i) {
     137        int i;
     138        size_t size = sizeof(processor.object_handles[0]) * src->objects_count;
     139        processor.object_handles = emalloc(size);
     140        IFAUTOCHECK(`xc_memsetptr(processor.object_handles, -1, size);')
     141        /* other objects in $object->properties after $object, reverse order is necessary */
     142        for (i = src->objects_count - 1; i >= 0; --i) {
    141143            zend_object *object = emalloc(sizeof(*object));
    142             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);
     144            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);
    143145            xc_restore_zend_object(&processor, object, &src->objects[i] TSRMLS_CC);
    144146        }
     
    154156        zend_uint i;
    155157        for (i = 0; i < src->objects_count; ++i) {
    156             zend_objects_store_del_ref_by_handle(xc_vector_data(zend_object_handle, &processor.object_handles)[i] TSRMLS_CC);
     158            zend_objects_store_del_ref_by_handle(processor.object_handles[i] TSRMLS_CC);
    157159        }
    158         xc_vector_destroy(&processor.object_handles);
     160        efree(processor.object_handles);
    159161    }
    160162#endif
  • trunk/processor/processor.m4

    r1567 r1568  
    14201420#ifdef ZEND_ENGINE_2
    14211421    IFCALC(`
    1422         dnl objects = collect_from(value);
     1422        dnl objects = collect_from(value + objects);
    14231423        pushdef(`src', `vsrc')
    1424         SRC(objects_count) = xc_vector_size(&processor->object_handles);
    1425         SRC(objects) = xc_vector_detach(zend_object, &processor->object_handles);
     1424        SRC(objects_count) = xc_vector_size(&processor->objects);
     1425        SRC(objects) = xc_vector_detach(zend_object, &processor->objects);
    14261426        popdef(`src')
    1427         xc_vector_destroy(&processor->object_handles);
     1427        xc_vector_destroy(&processor->objects);
    14281428    ')
    14291429    dnl must be after calc .value
     
    14431443    dnl classe_
    14441444    IFCALC(`
    1445         dnl class_names = collect_from(object_handles);
     1445        dnl class_names = collect_from(objects);
    14461446        pushdef(`src', `vsrc')
    14471447        SRC(class_names_count) = xc_vector_size(&processor->class_names);
  • trunk/processor/var-helper-t.h

    r1567 r1568  
    11/* {{{ var object helpers */
    22#ifdef ZEND_ENGINE_2
    3 xc_vector_t           object_handles;  /* in calc/restore only */
     3xc_vector_t           objects;         /* in calc */
    44HashTable             handle_to_index; /* in calc/store only */
     5zend_object_handle   *object_handles;  /* in restore only */
    56#endif
    67const xc_entry_var_t *entry_var_src;   /* in restore */
  • trunk/processor/var-helper.h

    r1567 r1568  
    11#ifdef ZEND_ENGINE_2
     2static void xc_var_collect_object(xc_processor_t *processor, zend_object_handle handle TSRMLS_DC);
     3static void xc_var_collect_object_in_zval(xc_processor_t *processor, zval *zv TSRMLS_DC);
     4static void xc_var_collect_object_in_hashtable(xc_processor_t *processor, HashTable *ht TSRMLS_DC);
     5
     6static void xc_var_collect_object_in_hashtable(xc_processor_t *processor, HashTable *ht TSRMLS_DC) /* {{{ */
     7{
     8    Bucket *bucket;
     9    for (bucket = ht->pListHead; bucket; bucket = bucket->pListNext) {
     10        xc_var_collect_object_in_zval(processor, *(zval **) bucket->pData TSRMLS_CC);
     11    }
     12}
     13/* }}} */
     14static void xc_var_collect_object_in_zval(xc_processor_t *processor, zval *zv TSRMLS_DC) /* {{{ */
     15{
     16    switch (Z_TYPE_P(zv)) {
     17    case IS_OBJECT:
     18        xc_var_collect_object(processor, Z_OBJ_HANDLE_P(zv) TSRMLS_CC);
     19        break;
     20
     21    case IS_ARRAY:
     22        xc_var_collect_object_in_hashtable(processor, Z_ARRVAL_P(zv) TSRMLS_CC);
     23        break;
     24    }
     25}
     26/* }}} */
    227static void xc_var_collect_object(xc_processor_t *processor, zend_object_handle handle TSRMLS_DC) /* {{{ */
    328{
    429    size_t next_index;
    530
    6     if (!xc_vector_initialized(&processor->object_handles)) {
    7         xc_vector_init(zend_object, &processor->object_handles);
     31    if (!xc_vector_initialized(&processor->objects)) {
     32        if (zend_hash_num_elements(&processor->handle_to_index)) {
     33            /* collecting process is stopped, may reach here by xc_entry_src_t.objects.properties */
     34            return;
     35        }
     36        xc_vector_init(zend_object, &processor->objects);
    837        zend_hash_init(&processor->handle_to_index, 0, NULL, NULL, 0);
    938    }
    1039
    11     next_index = xc_vector_size(&processor->object_handles);
     40    next_index = xc_vector_size(&processor->objects);
    1241    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) {
    1342        zend_object *object = zend_object_store_get_object_by_handle(handle TSRMLS_CC);
    14         xc_vector_push_back(&processor->object_handles, object);
     43
     44        xc_vector_push_back(&processor->objects, object);
     45
     46        if (object->properties) {
     47            xc_var_collect_object_in_hashtable(processor, object->properties TSRMLS_CC);
     48        }
     49
     50        /* TODO: is this necessary? */
     51        if (object->properties_table) {
     52            int i, count = zend_hash_num_elements(&object->ce->properties_info);
     53            for (i = 0; i < count; ++i) {
     54                xc_var_collect_object_in_zval(processor, object->properties_table[i] TSRMLS_CC);
     55            }
     56        }
    1557    }
    1658}
     
    3072static zend_object_handle xc_var_restore_handle(xc_processor_t *processor, size_t index TSRMLS_DC) /* {{{ */
    3173{
    32     zend_object_handle handle = xc_vector_data(zend_object_handle, &processor->object_handles)[index];
     74    zend_object_handle handle = processor->object_handles[index];
    3375    zend_objects_store_add_ref_by_handle(handle TSRMLS_CC);
    3476    return handle;
Note: See TracChangeset for help on using the changeset viewer.