Replaced glib memory allocation
This commit is contained in:
parent
6101b8c43a
commit
d5729efa1f
33 changed files with 414 additions and 166 deletions
|
|
@ -1,5 +1,24 @@
|
|||
#include <string.h>
|
||||
#include "parser_internal.h"
|
||||
|
||||
typedef unsigned int *HCharset;
|
||||
|
||||
static inline HCharset new_charset(HAllocator* mm__) {
|
||||
HCharset cs = h_new(unsigned int, 256 / sizeof(unsigned int));
|
||||
memset(cs, 0, 256);
|
||||
return cs;
|
||||
}
|
||||
|
||||
static inline int charset_isset(HCharset cs, uint8_t pos) {
|
||||
return !!(cs[pos / sizeof(*cs)] & (1 << (pos % sizeof(*cs))));
|
||||
}
|
||||
|
||||
static inline void charset_set(HCharset cs, uint8_t pos, int val) {
|
||||
cs[pos / sizeof(*cs)] =
|
||||
val
|
||||
? cs[pos / sizeof(*cs)] | (1 << (pos % sizeof(*cs)))
|
||||
: cs[pos / sizeof(*cs)] & ~(1 << (pos % sizeof(*cs)));
|
||||
}
|
||||
|
||||
static HParseResult* parse_charset(void *env, HParseState *state) {
|
||||
uint8_t in = h_read_bits(&state->input_stream, 8, false);
|
||||
|
|
@ -18,8 +37,11 @@ static const HParserVtable charset_vt = {
|
|||
};
|
||||
|
||||
const HParser* h_ch_range(const uint8_t lower, const uint8_t upper) {
|
||||
HParser *ret = g_new(HParser, 1);
|
||||
HCharset cs = new_charset();
|
||||
return h_ch_range__m(&system_allocator, lower, upper);
|
||||
}
|
||||
const HParser* h_ch_range__m(HAllocator* mm__, const uint8_t lower, const uint8_t upper) {
|
||||
HParser *ret = h_new(HParser, 1);
|
||||
HCharset cs = new_charset(mm__);
|
||||
for (int i = 0; i < 256; i++)
|
||||
charset_set(cs, i, (lower <= i) && (i <= upper));
|
||||
ret->vtable = &charset_vt;
|
||||
|
|
@ -28,9 +50,9 @@ const HParser* h_ch_range(const uint8_t lower, const uint8_t upper) {
|
|||
}
|
||||
|
||||
|
||||
const HParser* h_in_or_not(const uint8_t *options, size_t count, int val) {
|
||||
HParser *ret = g_new(HParser, 1);
|
||||
HCharset cs = new_charset();
|
||||
static const HParser* h_in_or_not__m(HAllocator* mm__, const uint8_t *options, size_t count, int val) {
|
||||
HParser *ret = h_new(HParser, 1);
|
||||
HCharset cs = new_charset(mm__);
|
||||
for (size_t i = 0; i < 256; i++)
|
||||
charset_set(cs, i, 1-val);
|
||||
for (size_t i = 0; i < count; i++)
|
||||
|
|
@ -42,10 +64,18 @@ const HParser* h_in_or_not(const uint8_t *options, size_t count, int val) {
|
|||
}
|
||||
|
||||
const HParser* h_in(const uint8_t *options, size_t count) {
|
||||
return h_in_or_not(options, count, 1);
|
||||
return h_in_or_not__m(&system_allocator, options, count, 1);
|
||||
}
|
||||
|
||||
const HParser* h_in__m(HAllocator* mm__, const uint8_t *options, size_t count) {
|
||||
return h_in_or_not__m(mm__, options, count, 1);
|
||||
}
|
||||
|
||||
const HParser* h_not_in(const uint8_t *options, size_t count) {
|
||||
return h_in_or_not(options, count, 0);
|
||||
return h_in_or_not__m(&system_allocator, options, count, 0);
|
||||
}
|
||||
|
||||
const HParser* h_not_in__m(HAllocator* mm__, const uint8_t *options, size_t count) {
|
||||
return h_in_or_not__m(mm__, options, count, 0);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue