[core] move data_{array,integer,string} to array.c
move native data_* types into array.c (the types are already declared in array.h) The array data structure remains extendable, as is done with data_config (configfile) and data_auth (mod_auth), though array data structure primary uses are at startup (config time) and header parsing. The insertion logic into sorted list can be expensive for large lists, so header parsing might choose a different data structure in the future.master
parent
fbe55825b4
commit
4f8f83ea1d
@ -1,51 +0,0 @@
|
||||
#include "first.h"
|
||||
|
||||
#include "array.h"
|
||||
#include "buffer.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
__attribute_cold__
|
||||
static data_unset *data_array_copy(const data_unset *s) {
|
||||
data_array *src = (data_array *)s;
|
||||
data_array *ds = data_array_init();
|
||||
|
||||
if (!buffer_is_empty(&src->key)) buffer_copy_buffer(&ds->key, &src->key);
|
||||
array_copy_array(&ds->value, &src->value);
|
||||
return (data_unset *)ds;
|
||||
}
|
||||
|
||||
static void data_array_free(data_unset *d) {
|
||||
data_array *ds = (data_array *)d;
|
||||
|
||||
free(ds->key.ptr);
|
||||
array_free_data(&ds->value);
|
||||
|
||||
free(d);
|
||||
}
|
||||
|
||||
__attribute_cold__
|
||||
static int data_array_insert_dup(data_unset *dst, data_unset *src) {
|
||||
UNUSED(dst);
|
||||
|
||||
src->fn->free(src);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
data_array *data_array_init(void) {
|
||||
static const struct data_methods fn = {
|
||||
data_array_copy,
|
||||
data_array_free,
|
||||
data_array_insert_dup,
|
||||
};
|
||||
data_array *ds;
|
||||
|
||||
ds = calloc(1, sizeof(*ds));
|
||||
force_assert(NULL != ds);
|
||||
|
||||
ds->type = TYPE_ARRAY;
|
||||
ds->fn = &fn;
|
||||
|
||||
return ds;
|
||||
}
|
@ -1,52 +0,0 @@
|
||||
#include "first.h"
|
||||
|
||||
#include "array.h"
|
||||
#include "buffer.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
__attribute_cold__
|
||||
static data_unset *data_integer_copy(const data_unset *s) {
|
||||
data_integer *src = (data_integer *)s;
|
||||
data_integer *ds = data_integer_init();
|
||||
|
||||
if (!buffer_is_empty(&src->key)) buffer_copy_buffer(&ds->key, &src->key);
|
||||
ds->value = src->value;
|
||||
return (data_unset *)ds;
|
||||
}
|
||||
|
||||
static void data_integer_free(data_unset *d) {
|
||||
data_integer *ds = (data_integer *)d;
|
||||
|
||||
free(ds->key.ptr);
|
||||
|
||||
free(d);
|
||||
}
|
||||
|
||||
__attribute_cold__
|
||||
static int data_integer_insert_dup(data_unset *dst, data_unset *src) {
|
||||
UNUSED(dst);
|
||||
|
||||
src->fn->free(src);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
data_integer *data_integer_init(void) {
|
||||
static const struct data_methods fn = {
|
||||
data_integer_copy,
|
||||
data_integer_free,
|
||||
data_integer_insert_dup,
|
||||
};
|
||||
data_integer *ds;
|
||||
|
||||
ds = calloc(1, sizeof(*ds));
|
||||
force_assert(NULL != ds);
|
||||
|
||||
ds->value = 0;
|
||||
|
||||
ds->type = TYPE_INTEGER;
|
||||
ds->fn = &fn;
|
||||
|
||||
return ds;
|
||||
}
|
@ -1,58 +0,0 @@
|
||||
#include "first.h"
|
||||
|
||||
#include "array.h"
|
||||
#include "buffer.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
__attribute_cold__
|
||||
static data_unset *data_string_copy(const data_unset *s) {
|
||||
data_string *src = (data_string *)s;
|
||||
data_string *ds = data_string_init();
|
||||
|
||||
if (!buffer_is_empty(&src->key)) buffer_copy_buffer(&ds->key, &src->key);
|
||||
buffer_copy_buffer(&ds->value, &src->value);
|
||||
return (data_unset *)ds;
|
||||
}
|
||||
|
||||
static void data_string_free(data_unset *d) {
|
||||
data_string *ds = (data_string *)d;
|
||||
|
||||
free(ds->key.ptr);
|
||||
free(ds->value.ptr);
|
||||
|
||||
free(d);
|
||||
}
|
||||
|
||||
__attribute_cold__
|
||||
static int data_string_insert_dup(data_unset *dst, data_unset *src) {
|
||||
data_string *ds_dst = (data_string *)dst;
|
||||
data_string *ds_src = (data_string *)src;
|
||||
|
||||
if (!buffer_is_empty(&ds_dst->value))
|
||||
buffer_append_str2(&ds_dst->value, CONST_STR_LEN(", "),
|
||||
CONST_BUF_LEN(&ds_src->value));
|
||||
else
|
||||
buffer_copy_buffer(&ds_dst->value, &ds_src->value);
|
||||
|
||||
src->fn->free(src);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
data_string *data_string_init(void) {
|
||||
static const struct data_methods fn = {
|
||||
data_string_copy,
|
||||
data_string_free,
|
||||
data_string_insert_dup,
|
||||
};
|
||||
data_string *ds;
|
||||
|
||||
ds = calloc(1, sizeof(*ds));
|
||||
force_assert(NULL != ds);
|
||||
|
||||
ds->type = TYPE_STRING;
|
||||
ds->fn = &fn;
|
||||
|
||||
return ds;
|
||||
}
|
Loading…
Reference in New Issue