Changeset 1567 in svn


Ignore:
Timestamp:
2014-11-11T17:10:13Z (4 years ago)
Author:
Xuefer
Message:

use vector for objects/object_handles

Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/mod_cacher/xc_cacher.c

    r1566 r1567  
    28282828        XG(php_holds) = calloc(XG(php_holds_size), sizeof(xc_vector_t));
    28292829        for (i = 0; i < xc_php_hcache.size; i ++) {
    2830             xc_vector_pinit(xc_entry_php_t *, &XG(php_holds[i]));
     2830            xc_vector_init_persistent(xc_entry_php_t *, &XG(php_holds[i]));
    28312831        }
    28322832    }
     
    28362836        XG(var_holds) = calloc(XG(var_holds_size), sizeof(xc_vector_t));
    28372837        for (i = 0; i < xc_var_hcache.size; i ++) {
    2838             xc_vector_pinit(xc_entry_php_t *, &XG(var_holds[i]));
     2838            xc_vector_init_persistent(xc_entry_php_t *, &XG(var_holds[i]));
    28392839        }
    28402840    }
  • trunk/processor/foot.m4

    r1566 r1567  
    136136    if (src->objects_count) {
    137137        zend_uint i;
    138         processor.object_handles = emalloc(sizeof(*processor.object_handles) * src->objects_count);
     138        xc_vector_init(zend_object_handle, &processor.object_handles);
     139        xc_vector_reserve(&processor.object_handles, src->objects_count);
    139140        for (i = 0; i < src->objects_count; ++i) {
    140141            zend_object *object = emalloc(sizeof(*object));
    141             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);
     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);
    142143            xc_restore_zend_object(&processor, object, &src->objects[i] TSRMLS_CC);
    143144        }
     
    153154        zend_uint i;
    154155        for (i = 0; i < src->objects_count; ++i) {
    155             zend_objects_store_del_ref_by_handle(processor.object_handles[i] TSRMLS_CC);
     156            zend_objects_store_del_ref_by_handle(xc_vector_data(zend_object_handle, &processor.object_handles)[i] TSRMLS_CC);
    156157        }
    157         efree(processor.object_handles);
     158        xc_vector_destroy(&processor.object_handles);
    158159    }
    159160#endif
  • trunk/processor/processor.m4

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

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

    r1566 r1567  
    44    size_t next_index;
    55
    6     if (!xc_vector_initialized(&processor->objects)) {
    7         xc_vector_init(zend_object, &processor->objects);
     6    if (!xc_vector_initialized(&processor->object_handles)) {
     7        xc_vector_init(zend_object, &processor->object_handles);
    88        zend_hash_init(&processor->handle_to_index, 0, NULL, NULL, 0);
    99    }
    1010
    11     next_index = xc_vector_size(&processor->objects);
     11    next_index = xc_vector_size(&processor->object_handles);
    1212    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) {
    1313        zend_object *object = zend_object_store_get_object_by_handle(handle TSRMLS_CC);
    14         xc_vector_push_back(&processor->objects, object);
     14        xc_vector_push_back(&processor->object_handles, object);
    1515    }
    1616}
     
    2121
    2222    if (zend_hash_index_find(&processor->handle_to_index, handle, (void **) &index) != SUCCESS) {
    23         php_error_docref(NULL TSRMLS_CC, E_CORE_ERROR, "Internal error: handle %d not found in objects", handle);
     23        php_error_docref(NULL TSRMLS_CC, E_CORE_ERROR, "Internal error: handle %d not found on store", handle);
    2424        return (size_t) -1;
    2525    }
     
    3030static zend_object_handle xc_var_restore_handle(xc_processor_t *processor, size_t index TSRMLS_DC) /* {{{ */
    3131{
    32     zend_object_handle handle = processor->object_handles[index];
     32    zend_object_handle handle = xc_vector_data(zend_object_handle, &processor->object_handles)[index];
    3333    zend_objects_store_add_ref_by_handle(handle TSRMLS_CC);
    3434    return handle;
  • trunk/util/xc_vector.h

    r1566 r1567  
    3636
    3737#define xc_vector_init(type, vector) xc_vector_init_ex(type, vector, NULL, 0, 0)
    38 #define xc_vector_pinit(type, vector) xc_vector_init_ex(type, vector, NULL, 0, 1)
     38#define xc_vector_init_persistent(type, vector) xc_vector_init_ex(type, vector, NULL, 0, 1)
    3939
    4040static inline void xc_vector_destroy_impl(xc_vector_t *vector TSRMLS_DC)
     
    6868#define xc_vector_data(type, vector) ((type *) xc_vector_check_type_(vector, sizeof(type))->data_)
    6969
     70static void xc_vector_reserve_impl(xc_vector_t *vector, size_t capacity TSRMLS_DC)
     71{
     72    assert(capacity);
     73    if (!vector->capacity_) {
     74        vector->capacity_ = 8;
     75    }
     76    while (vector->capacity_ <= capacity) {
     77        vector->capacity_ <<= 1;
     78    }
     79    vector->data_ = perealloc(vector->data_, vector->data_size_ * vector->capacity_, vector->persistent_);
     80}
     81#define xc_vector_reserve(vector, capacity) xc_vector_reserve_impl(vector, capacity TSRMLS_CC)
     82
     83static void xc_vector_resize_impl(xc_vector_t *vector, size_t size TSRMLS_DC)
     84{
     85    assert(size);
     86    xc_vector_reserve(vector, size);
     87    vector->size_ = size;
     88}
     89#define xc_vector_resize(vector, size) xc_vector_resize_impl(vector, size TSRMLS_CC)
     90
    7091static inline void xc_vector_check_reserve_(xc_vector_t *vector TSRMLS_DC)
    7192{
     
    7394        if (vector->capacity_) {
    7495            vector->capacity_ <<= 1;
    75             vector->data_ = perealloc(vector->data_, vector->data_size_ * vector->capacity_, vector->persistent_);
    7696        }
    7797        else {
    7898            vector->capacity_ = 8;
    79             vector->data_ = pemalloc(vector->data_size_ * vector->capacity_, vector->persistent_);
    8099        }
     100        vector->data_ = perealloc(vector->data_, vector->data_size_ * vector->capacity_, vector->persistent_);
    81101    }
    82102}
Note: See TracChangeset for help on using the changeset viewer.