summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/runtime/c/gu/seq.c66
-rw-r--r--src/runtime/c/gu/seq.h78
2 files changed, 56 insertions, 88 deletions
diff --git a/src/runtime/c/gu/seq.c b/src/runtime/c/gu/seq.c
index 65d1b945c..0bff675ac 100644
--- a/src/runtime/c/gu/seq.c
+++ b/src/runtime/c/gu/seq.c
@@ -7,30 +7,6 @@
#include <malloc.h>
#endif
-struct GuSeq {
- size_t len;
- uint8_t data[0];
-};
-
-struct GuBuf {
- GuSeq* seq;
- size_t elem_size;
- size_t avail_len;
- GuFinalizer fin;
-};
-
-size_t
-gu_buf_length(GuBuf* buf)
-{
- return buf->seq->len;
-}
-
-size_t
-gu_buf_avail(GuBuf* buf)
-{
- return buf->avail_len;
-}
-
static void
gu_buf_fini(GuFinalizer* fin)
{
@@ -51,18 +27,6 @@ gu_make_buf(size_t elem_size, GuPool* pool)
return buf;
}
-size_t
-gu_seq_length(GuSeq* seq)
-{
- return seq->len;
-}
-
-void*
-gu_seq_data(GuSeq* seq)
-{
- return seq->data;
-}
-
static GuSeq gu_empty_seq_ = {0};
GuSeq*
@@ -130,18 +94,6 @@ gu_buf_require(GuBuf* buf, size_t req_len)
}
void*
-gu_buf_data(GuBuf* buf)
-{
- return &buf->seq->data;
-}
-
-GuSeq*
-gu_buf_data_seq(GuBuf* buf)
-{
- return buf->seq;
-}
-
-void*
gu_buf_extend_n(GuBuf* buf, size_t n_elems)
{
size_t len = gu_buf_length(buf);
@@ -151,12 +103,6 @@ gu_buf_extend_n(GuBuf* buf, size_t n_elems)
return &buf->seq->data[buf->elem_size * len];
}
-void*
-gu_buf_extend(GuBuf* buf)
-{
- return gu_buf_extend_n(buf, 1);
-}
-
void
gu_buf_push_n(GuBuf* buf, const void* data, size_t n_elems)
{
@@ -173,18 +119,6 @@ gu_buf_trim_n(GuBuf* buf, size_t n_elems)
return &buf->seq->data[buf->elem_size * new_len];
}
-const void*
-gu_buf_trim(GuBuf* buf)
-{
- return gu_buf_trim_n(buf, 1);
-}
-
-void
-gu_buf_flush(GuBuf* buf)
-{
- buf->seq->len = 0;
-}
-
void
gu_buf_pop_n(GuBuf* buf, size_t n_elems, void* data_out)
{
diff --git a/src/runtime/c/gu/seq.h b/src/runtime/c/gu/seq.h
index 3143906f2..25af2b068 100644
--- a/src/runtime/c/gu/seq.h
+++ b/src/runtime/c/gu/seq.h
@@ -3,9 +3,17 @@
#include <gu/mem.h>
-typedef struct GuBuf GuBuf;
-
-typedef struct GuSeq GuSeq;
+typedef struct {
+ size_t len;
+ uint8_t data[0];
+} GuSeq;
+
+typedef struct {
+ GuSeq* seq;
+ size_t elem_size;
+ size_t avail_len;
+ GuFinalizer fin;
+} GuBuf;
GuSeq*
gu_empty_seq();
@@ -31,12 +39,17 @@ gu_realloc_seq_(GuSeq* seq, size_t elem_size, size_t length);
void
gu_seq_free(GuSeq* seq);
-size_t
-gu_seq_length(GuSeq* seq);
-
-void*
-gu_seq_data(GuSeq* seq);
+inline size_t
+gu_seq_length(GuSeq* seq)
+{
+ return seq->len;
+}
+inline void*
+gu_seq_data(GuSeq* seq)
+{
+ return seq->data;
+}
#define gu_seq_index(SEQ, T, I) \
(&((T*)gu_seq_data(SEQ))[I])
@@ -56,17 +69,29 @@ gu_make_buf(size_t elem_size, GuPool* pool);
#define gu_new_buf(T, POOL) \
gu_make_buf(sizeof(T), (POOL))
-size_t
-gu_buf_length(GuBuf* buf);
+inline size_t
+gu_buf_length(GuBuf* buf)
+{
+ return buf->seq->len;
+}
-size_t
-gu_buf_avail(GuBuf* buf);
+inline size_t
+gu_buf_avail(GuBuf* buf)
+{
+ return buf->avail_len;
+}
-void*
-gu_buf_data(GuBuf* buf);
+inline void*
+gu_buf_data(GuBuf* buf)
+{
+ return &buf->seq->data;
+}
-GuSeq*
-gu_buf_data_seq(GuBuf* buf);
+inline GuSeq*
+gu_buf_data_seq(GuBuf* buf)
+{
+ return buf->seq;
+}
#define gu_buf_index(BUF, T, I) \
(&((T*)gu_buf_data(BUF))[I])
@@ -85,8 +110,11 @@ gu_buf_push_n(GuBuf* buf, const void* elems, size_t n_elems);
void*
gu_buf_extend_n(GuBuf* buf, size_t n_elems);
-void*
-gu_buf_extend(GuBuf* buf);
+inline void*
+gu_buf_extend(GuBuf* buf)
+{
+ return gu_buf_extend_n(buf, 1);
+}
#define gu_buf_push(BUF, T, VAL) \
GU_BEGIN \
@@ -99,14 +127,20 @@ gu_buf_pop_n(GuBuf* buf, size_t n_elems, void* data_out);
const void*
gu_buf_trim_n(GuBuf* buf, size_t n_elems);
-const void*
-gu_buf_trim(GuBuf* buf);
+inline const void*
+gu_buf_trim(GuBuf* buf)
+{
+ return gu_buf_trim_n(buf, 1);
+}
void*
gu_buf_insert(GuBuf* buf, size_t n_index);
-void
-gu_buf_flush(GuBuf* buf);
+inline void
+gu_buf_flush(GuBuf* buf)
+{
+ buf->seq->len = 0;
+}
#define gu_buf_pop(BUF, T) \
(*(T*)gu_buf_trim(BUF))