Skip to content

Commit

Permalink
refactor(chain): use function templates to define functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Water-Melon committed Feb 3, 2024
1 parent 62b1dc1 commit a2f45a7
Showing 1 changed file with 11 additions and 15 deletions.
26 changes: 11 additions & 15 deletions src/mln_chain.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
*/

#include "mln_chain.h"
#include "mln_func.h"

mln_buf_t *mln_buf_new(mln_alloc_t *pool)
{
MLN_FUNC(mln_buf_t *, mln_buf_new, (mln_alloc_t *pool), (pool), {
mln_buf_t *b = mln_alloc_m(pool, sizeof(mln_buf_t));
b->left_pos = b->pos = b->last = NULL;
b->start = b->end = NULL;
Expand All @@ -19,18 +19,16 @@ mln_buf_t *mln_buf_new(mln_alloc_t *pool)
#endif
b->flush = b->sync = b->last_buf = b->last_in_chain = 0;
return b;
}
})

mln_chain_t *mln_chain_new(mln_alloc_t *pool)
{
MLN_FUNC(mln_chain_t *, mln_chain_new, (mln_alloc_t *pool), (pool), {
mln_chain_t *c = mln_alloc_m(pool, sizeof(mln_chain_t));
c->buf = NULL;
c->next = NULL;
return c;
}
})

void mln_buf_pool_release(mln_buf_t *b)
{
MLN_FUNC_VOID(void, mln_buf_pool_release, (mln_buf_t *b), (b), {
if (b == NULL) return;

if (b->shadow != NULL || b->temporary) {
Expand Down Expand Up @@ -67,26 +65,24 @@ void mln_buf_pool_release(mln_buf_t *b)
}

mln_alloc_free(b);
}
})

void mln_chain_pool_release(mln_chain_t *c)
{
MLN_FUNC_VOID(void, mln_chain_pool_release, (mln_chain_t *c), (c), {
if (c == NULL) return;

if (c->buf != NULL) {
mln_buf_pool_release(c->buf);
}
mln_alloc_free(c);
}
})

void mln_chain_pool_release_all(mln_chain_t *c)
{
MLN_FUNC_VOID(void, mln_chain_pool_release_all, (mln_chain_t *c), (c), {
mln_chain_t *fr;

while (c != NULL) {
fr = c;
c = c->next;
mln_chain_pool_release(fr);
}
}
})

0 comments on commit a2f45a7

Please sign in to comment.