Remove unused memory pool

This commit is contained in:
Björn Svensson 2021-11-03 14:14:07 +01:00
parent e533bae646
commit f0dd25bd53
6 changed files with 19 additions and 24 deletions

View file

@ -253,10 +253,10 @@ void r3_buffer__dispose_linked(void *p);
* @param element_size size of the elements stored in the vector * @param element_size size of the elements stored in the vector
* @param new_capacity the capacity of the buffer after the function returns * @param new_capacity the capacity of the buffer after the function returns
*/ */
#define r3_vector_reserve(pool, vector, new_capacity) \ #define r3_vector_reserve(vector, new_capacity) \
r3_vector__reserve((pool), (r3_vector_t *)(void *)(vector), sizeof((vector)->entries[0]), (new_capacity)) r3_vector__reserve((r3_vector_t *)(void *)(vector), sizeof((vector)->entries[0]), (new_capacity))
static void r3_vector__reserve(r3_mem_pool_t *pool, r3_vector_t *vector, unsigned int element_size, unsigned int new_capacity); static void r3_vector__reserve(r3_vector_t *vector, unsigned int element_size, unsigned int new_capacity);
void r3_vector__expand(r3_mem_pool_t *pool, r3_vector_t *vector, unsigned int element_size, unsigned int new_capacity); void r3_vector__expand(r3_vector_t *vector, unsigned int element_size, unsigned int new_capacity);
/** /**
* tests if target chunk (target_len bytes long) is equal to test chunk (test_len bytes long) * tests if target chunk (target_len bytes long) is equal to test chunk (test_len bytes long)
@ -358,10 +358,10 @@ inline void r3_buffer_link_to_pool(r3_buffer_t *buffer, r3_mem_pool_t *pool)
*slot = buffer; *slot = buffer;
} }
inline void r3_vector__reserve(r3_mem_pool_t *pool, r3_vector_t *vector, unsigned int element_size, unsigned int new_capacity) inline void r3_vector__reserve(r3_vector_t *vector, unsigned int element_size, unsigned int new_capacity)
{ {
if (vector->capacity < new_capacity) { if (vector->capacity < new_capacity) {
r3_vector__expand(pool, vector, element_size, new_capacity); r3_vector__expand(vector, element_size, new_capacity);
} }
} }

View file

@ -17,7 +17,7 @@
match_entry * match_entry_createl(const char * path, int path_len) { match_entry * match_entry_createl(const char * path, int path_len) {
match_entry * entry = r3_mem_alloc( sizeof(match_entry) ); match_entry * entry = r3_mem_alloc( sizeof(match_entry) );
memset(entry, 0, sizeof(*entry)); memset(entry, 0, sizeof(*entry));
r3_vector_reserve(NULL, &entry->vars.tokens, 3); r3_vector_reserve(&entry->vars.tokens, 3);
entry->path.base = path; entry->path.base = path;
entry->path.len = path_len; entry->path.len = path_len;
return entry; return entry;

View file

@ -316,7 +316,7 @@ void r3_buffer__dispose_linked(void *p)
r3_buffer_dispose(buf); r3_buffer_dispose(buf);
} }
void r3_vector__expand(r3_mem_pool_t *pool, r3_vector_t *vector, unsigned int element_size, unsigned int new_capacity) void r3_vector__expand(r3_vector_t *vector, unsigned int element_size, unsigned int new_capacity)
{ {
void *new_entries; void *new_entries;
assert(vector->capacity < new_capacity); assert(vector->capacity < new_capacity);
@ -324,12 +324,7 @@ void r3_vector__expand(r3_mem_pool_t *pool, r3_vector_t *vector, unsigned int el
vector->capacity = 4; vector->capacity = 4;
while (vector->capacity < new_capacity) while (vector->capacity < new_capacity)
vector->capacity *= 2; vector->capacity *= 2;
if (pool) {
new_entries = r3_mem_alloc_pool(pool, element_size * vector->capacity);
memcpy(new_entries, vector->entries, element_size * vector->size);
} else {
new_entries = r3_mem_realloc(vector->entries, element_size * vector->capacity); new_entries = r3_mem_realloc(vector->entries, element_size * vector->capacity);
}
vector->entries = new_entries; vector->entries = new_entries;
} }

View file

@ -57,9 +57,9 @@ R3Node * r3_tree_create(int cap) {
R3Node * n = r3_mem_alloc( sizeof(R3Node) ); R3Node * n = r3_mem_alloc( sizeof(R3Node) );
memset(n, 0, sizeof(*n)); memset(n, 0, sizeof(*n));
r3_vector_reserve(NULL, &n->edges, n->edges.size + cap); r3_vector_reserve(&n->edges, n->edges.size + cap);
r3_vector_reserve(NULL, &n->routes, n->routes.size + 1); r3_vector_reserve(&n->routes, n->routes.size + 1);
n->compare_type = NODE_COMPARE_PCRE; n->compare_type = NODE_COMPARE_PCRE;
return n; return n;
@ -111,7 +111,7 @@ R3Edge * r3_node_connectl(R3Node * n, const char * pat, int len, int dupl, R3Nod
R3Edge * r3_node_append_edge(R3Node *n) R3Edge * r3_node_append_edge(R3Node *n)
{ {
r3_vector_reserve(NULL, &n->edges, n->edges.size + 1); r3_vector_reserve(&n->edges, n->edges.size + 1);
R3Edge *new_e = n->edges.entries + n->edges.size++; R3Edge *new_e = n->edges.entries + n->edges.size++;
memset(new_e, 0, sizeof(*new_e)); memset(new_e, 0, sizeof(*new_e));
return new_e; return new_e;
@ -542,7 +542,7 @@ void r3_route_free(R3Route * route) {
static r3_iovec_t* router_append_slug(R3Route * route, const char * slug, unsigned int len) { static r3_iovec_t* router_append_slug(R3Route * route, const char * slug, unsigned int len) {
r3_iovec_t *temp; r3_iovec_t *temp;
r3_vector_reserve(NULL, &route->slugs, route->slugs.size + 1); r3_vector_reserve(&route->slugs, route->slugs.size + 1);
temp = route->slugs.entries + route->slugs.size++; temp = route->slugs.entries + route->slugs.size++;
temp->base = slug; temp->base = slug;
temp->len = len; temp->len = len;
@ -565,11 +565,11 @@ static void get_slugs(R3Route * route, const char * path, int path_len) {
} }
R3Route * r3_node_append_route(R3Node *tree, const char * path, int path_len, int method, void *data) { R3Route * r3_node_append_route(R3Node *tree, const char * path, int path_len, int method, void *data) {
r3_vector_reserve(NULL, &tree->routes, tree->routes.size + 1); r3_vector_reserve(&tree->routes, tree->routes.size + 1);
R3Route *info = tree->routes.entries + tree->routes.size++; R3Route *info = tree->routes.entries + tree->routes.size++;
memset(info, 0, sizeof(*info)); memset(info, 0, sizeof(*info));
r3_vector_reserve(NULL, &info->slugs, info->slugs.size + 3); r3_vector_reserve(&info->slugs, info->slugs.size + 3);
info->path.base = (char*) path; info->path.base = (char*) path;
info->path.len = path_len; info->path.len = path_len;
info->request_method = method; // ALLOW GET OR POST METHOD info->request_method = method; // ALLOW GET OR POST METHOD
@ -998,7 +998,7 @@ inline int r3_route_cmp(const R3Route *r1, const match_entry *r2) {
*/ */
// void r3_node_append_route(R3Node * n, R3Route * r) // void r3_node_append_route(R3Node * n, R3Route * r)
// { // {
// r3_vector_reserve(NULL, &n->routes, n->routes.size + 1); // r3_vector_reserve(&n->routes, n->routes.size + 1);
// memset(n->routes.entries + 1, 0, sizeof(*n->routes.entries)); // memset(n->routes.entries + 1, 0, sizeof(*n->routes.entries));
// if (n->routes == NULL) { // if (n->routes == NULL) {

View file

@ -20,7 +20,7 @@ void str_array_free(str_array *l) {
} }
bool str_array_append(str_array * l, const char * token, unsigned int len) { bool str_array_append(str_array * l, const char * token, unsigned int len) {
r3_vector_reserve(NULL, &l->tokens, l->tokens.size + 1); r3_vector_reserve(&l->tokens, l->tokens.size + 1);
r3_iovec_t *temp = l->tokens.entries + l->tokens.size++; r3_iovec_t *temp = l->tokens.entries + l->tokens.size++;
memset(temp, 0, sizeof(*temp)); memset(temp, 0, sizeof(*temp));
temp->base = token; temp->base = token;

View file

@ -43,7 +43,7 @@ START_TEST (test_access_macros)
ck_assert( str_array_len(vars) == 0); ck_assert( str_array_len(vars) == 0);
ck_assert( str_array_cap(vars) == 0); ck_assert( str_array_cap(vars) == 0);
r3_vector_reserve(NULL, &vars->tokens, 4); r3_vector_reserve(&vars->tokens, 4);
ck_assert( str_array_len(vars) == 0); ck_assert( str_array_len(vars) == 0);
ck_assert( str_array_cap(vars) == 4); ck_assert( str_array_cap(vars) == 4);