Fix calls of the inline methods
This commit is contained in:
parent
2118404bfe
commit
e92ff17be4
@ -13,15 +13,13 @@ arr_t array_copy(const arr_t* s) {
|
||||
|
||||
if (s->type >= VTYPE_STRING) {
|
||||
void *p, *v, *e;
|
||||
type_initializer init;
|
||||
|
||||
x.mem = p = malloc(x.size*vtype_size(x.type));
|
||||
v = s->mem;
|
||||
e = array_end(&x);
|
||||
init = get_type_initializer(s->type);
|
||||
|
||||
do {
|
||||
init(p, v);
|
||||
copy_init(p, v, s->type);
|
||||
p += vtype_size(x.type);
|
||||
v += vtype_size(x.type);
|
||||
} while (p < e);
|
||||
@ -42,15 +40,13 @@ arr_t* array_duplicate(const arr_t* s) {
|
||||
|
||||
if (s->type >= VTYPE_STRING) {
|
||||
void *p, *v, *e;
|
||||
type_initializer init;
|
||||
|
||||
x->mem = p = malloc(x->size*vtype_size(x->type));
|
||||
v = s->mem;
|
||||
e = array_end(x);
|
||||
init = get_type_initializer(s->type);
|
||||
|
||||
do {
|
||||
init(p, v);
|
||||
copy_init(p, v, s->type);
|
||||
p += vtype_size(x->type);
|
||||
v += vtype_size(x->type);
|
||||
} while (p < e);
|
||||
@ -69,15 +65,13 @@ void array_copy_init(arr_t* x, const arr_t* s) {
|
||||
|
||||
if (s->type >= VTYPE_STRING) {
|
||||
void *p, *v, *e;
|
||||
type_initializer init;
|
||||
|
||||
x->mem = p = malloc(x->size*vtype_size(x->type));
|
||||
v = s->mem;
|
||||
e = array_end(x);
|
||||
init = get_type_initializer(s->type);
|
||||
|
||||
do {
|
||||
init(p, v);
|
||||
copy_init(p, v, s->type);
|
||||
p += vtype_size(x->type);
|
||||
v += vtype_size(x->type);
|
||||
} while (p < e);
|
||||
@ -103,15 +97,13 @@ size_t array_slice(arr_t* x, arr_t* s, ssize_t i, size_t n, _Bool cut) {
|
||||
|
||||
if (!cut && s->type >= VTYPE_STRING) {
|
||||
void *p, *v, *e;
|
||||
type_initializer init;
|
||||
|
||||
p = x->mem;
|
||||
v = array_internal_at(s, i);
|
||||
e = array_internal_at(x, n);
|
||||
init = get_type_initializer(s->type);
|
||||
|
||||
do {
|
||||
init(p, v);
|
||||
copy_init(p, v, s->type);
|
||||
p += vtype_size(x->type);
|
||||
v += vtype_size(x->type);
|
||||
} while (p < e);
|
||||
|
@ -7,20 +7,18 @@
|
||||
#ifndef LIBCDSB_SRC_ARRAY_INCLUDE_H
|
||||
#define LIBCDSB_SRC_ARRAY_INCLUDE_H
|
||||
|
||||
typedef void (*type_initializer)(void*, const void*);
|
||||
|
||||
ainline(type_initializer get_type_initializer(vtype type)) {
|
||||
switch (type) {
|
||||
ainline(void copy_init(void* x, const void* s, vtype t)) {
|
||||
switch (t) {
|
||||
default:
|
||||
#ifndef NDEBUG
|
||||
abort();
|
||||
#endif
|
||||
case VTYPE_STRING: return (void*)string_copy_init;
|
||||
case VTYPE_ARRAY: return (void*) array_copy_init;
|
||||
case VTYPE_LIST: return (void*) list_copy_init;
|
||||
case VTYPE_MAP: return (void*) map_copy_init;
|
||||
case VTYPE_SET: return (void*) vset_copy_init;
|
||||
case VTYPE_DICT: return (void*) dict_copy_init;
|
||||
case VTYPE_STRING: string_copy_init(x, s); break;
|
||||
case VTYPE_ARRAY: array_copy_init(x, s); break;
|
||||
case VTYPE_LIST: list_copy_init(x, s); break;
|
||||
case VTYPE_MAP: map_copy_init(x, s); break;
|
||||
case VTYPE_SET: vset_copy_init(x, s); break;
|
||||
case VTYPE_DICT: dict_copy_init(x, s); break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4,36 +4,25 @@
|
||||
#include "include.h"
|
||||
#include "../__internal/assert.h"
|
||||
|
||||
typedef void (*type_free)(void*);
|
||||
void array_free(arr_t* x) {
|
||||
if (x->size && x->type >= VTYPE_STRING) {
|
||||
void* p = x->mem;
|
||||
|
||||
static inline type_free get_type_free(vtype type) {
|
||||
switch (type) {
|
||||
assert(!is_null(p));
|
||||
|
||||
do {
|
||||
switch (x->type) {
|
||||
default:
|
||||
#ifndef NDEBUG
|
||||
abort();
|
||||
#endif
|
||||
case VTYPE_STRING: return (void*)string_free;
|
||||
case VTYPE_ARRAY: return (void*) array_free;
|
||||
case VTYPE_LIST: return (void*) list_free;
|
||||
case VTYPE_MAP: return (void*) map_free;
|
||||
case VTYPE_SET: return (void*) vset_free;
|
||||
case VTYPE_DICT: return (void*) dict_free;
|
||||
case VTYPE_STRING: string_free(p); break;
|
||||
case VTYPE_ARRAY: array_free(p); break;
|
||||
case VTYPE_LIST: list_free(p); break;
|
||||
case VTYPE_MAP: map_free(p); break;
|
||||
case VTYPE_SET: vset_free(p); break;
|
||||
case VTYPE_DICT: dict_free(p); break;
|
||||
}
|
||||
}
|
||||
|
||||
/*#####################################################################################################################*/
|
||||
|
||||
void array_free(arr_t* x) {
|
||||
if (x->size && x->type >= VTYPE_STRING) {
|
||||
void* p = x->mem;
|
||||
type_free free_;
|
||||
|
||||
assert(!is_null(p));
|
||||
|
||||
free_ = get_type_free(x->type);
|
||||
|
||||
do {
|
||||
free_(p);
|
||||
p += vtype_size(x->type);
|
||||
} while (--x->size);
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ ssize_t libcdsb_array_insert(arr_t* x, const void* v, vtype t) {
|
||||
|
||||
} else {
|
||||
type_assert(x->type, t);
|
||||
get_type_initializer(t)(array_internal_at(x, i), v);
|
||||
copy_init(array_internal_at(x, i), v, t);
|
||||
}
|
||||
|
||||
return i;
|
||||
|
Loading…
Reference in New Issue
Block a user