summaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorXuefer <xuefer@gmail.com>2014-11-11 17:10:13 +0000
committerXuefer <xuefer@gmail.com>2014-11-11 17:10:13 +0000
commit07183575efa06f2c59303739f45f7bb4c1791ca0 (patch)
tree0282f4888b8d5715f45ed2a14a9de4ef7cfdb7b9 /util
parent30d56bf2d775fa30aa116778bb342a45b654e0a7 (diff)
downloadxcache-07183575efa06f2c59303739f45f7bb4c1791ca0.tar.gz
xcache-07183575efa06f2c59303739f45f7bb4c1791ca0.zip
use vector for objects/object_handles
git-svn-id: svn://svn.lighttpd.net/xcache/trunk@1567 c26eb9a1-5813-0410-bd6c-c2e55f420ca7
Diffstat (limited to 'util')
-rw-r--r--util/xc_vector.h26
1 files changed, 23 insertions, 3 deletions
diff --git a/util/xc_vector.h b/util/xc_vector.h
index aab8a0c..15e9ef7 100644
--- a/util/xc_vector.h
+++ b/util/xc_vector.h
@@ -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_);
}
}