Changeset 1566 in svn


Ignore:
Timestamp:
2014-11-11T16:09:55Z (4 years ago)
Author:
Xuefer
Message:

code clean up for vector

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/mod_cacher/xc_cacher.c

    r1561 r1566  
    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_init(xc_entry_php_t *, &XG(php_holds[i]), 1);
     2830            xc_vector_pinit(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_init(xc_entry_php_t *, &XG(var_holds[i]), 1);
     2838            xc_vector_pinit(xc_entry_php_t *, &XG(var_holds[i]));
    28392839        }
    28402840    }
  • trunk/processor/foot.m4

    r1565 r1566  
    1313    processor.relocatediff = storage->relocatediff;
    1414
    15     IFAUTOCHECK(`xc_vector_init(unsigned long, &processor.allocsizes, 0);')
     15    IFAUTOCHECK(`xc_vector_init(unsigned long, &processor.allocsizes);')
    1616
    1717    /* calc size */ {
  • trunk/processor/var-helper.h

    r1564 r1566  
    55
    66    if (!xc_vector_initialized(&processor->objects)) {
    7         xc_vector_init(zend_object, &processor->objects, 0);
     7        xc_vector_init(zend_object, &processor->objects);
    88        zend_hash_init(&processor->handle_to_index, 0, NULL, NULL, 0);
    99    }
     
    4141
    4242    if (!xc_vector_initialized(&processor->class_names)) {
    43         xc_vector_init(xc_constant_string_t, &processor->class_names, 0);
     43        xc_vector_init(xc_constant_string_t, &processor->class_names);
    4444        zend_hash_init(&processor->class_name_to_index, 0, NULL, NULL, 0);
    4545    }
  • trunk/util/xc_vector.h

    r1560 r1566  
    1111
    1212typedef struct {
    13     size_t size;
    14     void *data;
     13    void *data_;
     14    size_t size_;
     15    size_t capacity_;
    1516
    16     size_t capacity;
    17     size_t data_size;
    18     int persistent;
     17    size_t data_size_;
     18    int persistent_;
    1919} xc_vector_t;
    2020
    21 #define xc_vector_initializer(type, persistent_) { \
     21#define xc_vector_initializer(type, persistent) { \
     22    NULL, \
    2223    0, \
    23     NULL, \
     24    0, \
    2425\
    25     0, \
    2626    sizeof(type), \
    27     persistent_, \
     27    persistent, \
    2828}
    2929
    30 #define xc_vector_init(type, vector, persistent_) do { \
    31     (vector)->size = 0; \
    32     (vector)->data = NULL; \
    33 \
    34     (vector)->capacity = 0; \
    35     (vector)->data_size = sizeof(type); \
    36     (vector)->persistent = persistent_; \
     30#define xc_vector_init_ex(type, vector, data, size, persistent) do { \
     31    (vector)->data_ = data; \
     32    (vector)->size_ = (vector)->capacity_ = size; \
     33    (vector)->data_size_ = sizeof(type); \
     34    (vector)->persistent_ = persistent; \
    3735} while (0)
     36
     37#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)
    3839
    3940static inline void xc_vector_destroy_impl(xc_vector_t *vector TSRMLS_DC)
    4041{
    41     vector->size = 0;
    42     if (vector->data) {
    43         pefree(vector->data, vector->persistent);
    44         vector->data = NULL;
     42    vector->size_ = 0;
     43    if (vector->data_) {
     44        pefree(vector->data_, vector->persistent_);
     45        vector->data_ = NULL;
    4546    }
    46     vector->capacity = 0;
    47     vector->data_size = 0;
     47    vector->capacity_ = 0;
     48    vector->data_size_ = 0;
    4849}
    4950
    5051#define xc_vector_destroy(vector) xc_vector_destroy_impl(vector TSRMLS_CC)
    51 #define xc_vector_clear(vector) do { (vector)->size = 0; } while (0)
     52#define xc_vector_clear(vector) do { (vector)->size_ = 0; } while (0)
    5253
    53 #define xc_vector_size(vector) ((vector)->size)
    54 #define xc_vector_initialized(vector) ((vector)->data_size != 0)
     54#define xc_vector_size(vector) ((vector)->size_)
     55#define xc_vector_initialized(vector) ((vector)->data_size_ != 0)
    5556#define xc_vector_element_ptr_(vector, index) ( \
    5657    (void *) ( \
    57         ((char *) (vector)->data) + (index) * (vector)->data_size \
     58        ((char *) (vector)->data_) + (index) * (vector)->data_size_ \
    5859    ) \
    5960)
     
    6162static inline xc_vector_t *xc_vector_check_type_(xc_vector_t *vector, size_t data_size)
    6263{
    63     assert(vector->data_size = data_size);
     64    assert(vector->data_size_ = data_size);
    6465    return vector;
    6566}
    6667
    67 #define xc_vector_data(type, vector) ((type *) xc_vector_check_type_(vector, sizeof(type))->data)
     68#define xc_vector_data(type, vector) ((type *) xc_vector_check_type_(vector, sizeof(type))->data_)
    6869
    6970static inline void xc_vector_check_reserve_(xc_vector_t *vector TSRMLS_DC)
    7071{
    71     if (vector->size == vector->capacity) {
    72         if (vector->capacity) {
    73             vector->capacity <<= 1;
    74             vector->data = perealloc(vector->data, vector->data_size * vector->capacity, vector->persistent);
     72    if (vector->size_ == vector->capacity_) {
     73        if (vector->capacity_) {
     74            vector->capacity_ <<= 1;
     75            vector->data_ = perealloc(vector->data_, vector->data_size_ * vector->capacity_, vector->persistent_);
    7576        }
    7677        else {
    77             vector->capacity = 8;
    78             vector->data = pemalloc(vector->data_size * vector->capacity, vector->persistent);
     78            vector->capacity_ = 8;
     79            vector->data_ = pemalloc(vector->data_size_ * vector->capacity_, vector->persistent_);
    7980        }
    8081    }
     
    8384#define xc_vector_push_back(vector, value_ptr) do { \
    8485    xc_vector_check_reserve_(vector TSRMLS_CC); \
    85     memcpy(xc_vector_element_ptr_(vector, (vector)->size++), value_ptr, (vector)->data_size); \
     86    memcpy(xc_vector_element_ptr_(vector, (vector)->size_++), value_ptr, (vector)->data_size_); \
    8687} while (0)
    8788
    8889static inline void *xc_vector_detach_impl(xc_vector_t *vector)
    8990{
    90     void *data = vector->data;
     91    void *data = vector->data_;
    9192
    92     vector->data = NULL;
    93     vector->capacity = 0;
    94     vector->size = 0;
     93    vector->data_ = NULL;
     94    vector->capacity_ = 0;
     95    vector->size_ = 0;
    9596    return data;
    9697}
     
    101102{
    102103    assert(vector);
    103     assert(vector->data_size == data_size);
    104     assert(vector->capacity > 0);
     104    assert(vector->data_size_ == data_size);
     105    assert(vector->capacity_ > 0);
    105106    return vector;
    106107}
     
    108109#define xc_vector_pop_back(type, vector) xc_vector_data(type, \
    109110    xc_vector_pop_back_check_(vector, sizeof(type)) \
    110 )[--(vector)->size]
     111)[--(vector)->size_]
    111112
    112113static inline void xc_vector_reverse(xc_vector_t *vector)
     
    116117
    117118    assert(vector);
    118     tmp = alloca(vector->data_size);
    119     for (left = vector->data, right = xc_vector_element_ptr_(vector, vector->size - 1); left < right; left += vector->data_size, right -= vector->data_size) {
    120         memcpy(tmp, left, vector->data_size);
    121         memcpy(left, right, vector->data_size);
    122         memcpy(right, tmp, vector->data_size);
     119    assert(vector->data_size_);
     120    tmp = alloca(vector->data_size_);
     121    for (left = vector->data_, right = xc_vector_element_ptr_(vector, vector->size_ - 1); left < right; left += vector->data_size_, right -= vector->data_size_) {
     122        memcpy(tmp, left, vector->data_size_);
     123        memcpy(left, right, vector->data_size_);
     124        memcpy(right, tmp, vector->data_size_);
    123125    }
    124126}
Note: See TracChangeset for help on using the changeset viewer.