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