diff options
Diffstat (limited to 'src/runtime/c')
| -rw-r--r-- | src/runtime/c/gu/seq.c | 14 | ||||
| -rw-r--r-- | src/runtime/c/gu/seq.h | 3 |
2 files changed, 17 insertions, 0 deletions
diff --git a/src/runtime/c/gu/seq.c b/src/runtime/c/gu/seq.c index 085bdb8a6..5f0171977 100644 --- a/src/runtime/c/gu/seq.c +++ b/src/runtime/c/gu/seq.c @@ -201,6 +201,20 @@ gu_buf_freeze(GuBuf* buf, GuPool* pool) return seq; } +void* +gu_buf_insert(GuBuf* buf, size_t index) +{ + size_t len = buf->seq->len; + gu_buf_require(buf, len + 1); + + uint8_t* target = + buf->seq->data + buf->elem_size * index; + memmove(target+buf->elem_size, target, (len-index)*buf->elem_size); + + buf->seq->len++; + return target; +} + static void gu_quick_sort(GuBuf *buf, GuOrder *order, int left, int right) { diff --git a/src/runtime/c/gu/seq.h b/src/runtime/c/gu/seq.h index 99642a303..5accb0b24 100644 --- a/src/runtime/c/gu/seq.h +++ b/src/runtime/c/gu/seq.h @@ -102,6 +102,9 @@ gu_buf_trim_n(GuBuf* buf, size_t n_elems); const void* gu_buf_trim(GuBuf* buf); +void* +gu_buf_insert(GuBuf* buf, size_t n_index); + void gu_buf_flush(GuBuf* buf); |
