Changeset 1567 in svn for trunk/util/xc_vector.h


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

use vector for objects/object_handles

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.