From: Jérémie Astor Date: Tue, 26 Jan 2021 19:11:28 +0000 (+0100) Subject: :art: Few updates X-Git-Tag: nightly~1021 X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=ebf4c49f0789639276643d1cf6315e423c9cf798;p=gwion.git :art: Few updates --- diff --git a/include/object.h b/include/object.h index af7043e2..04c975ee 100644 --- a/include/object.h +++ b/include/object.h @@ -25,7 +25,7 @@ ANN void broadcast(const M_Object); #define STRING(o) (*(m_str*) ((M_Object)o)->data) #define ME(o) (*(VM_Shred*) ((M_Object)o)->data) -#define EV_SHREDS(o) (*(Vector*) ((M_Object)o)->data) +#define EV_SHREDS(o) (*(struct Vector_*) ((M_Object)o)->data) #define UGEN(o) (*(UGen*) ((M_Object)o)->data) #define ARRAY(o) (*(M_Vector*) ((M_Object)o)->data) #define IO_FILE(o) (*(FILE**) (((M_Object)o)->data + SZ_INT)) diff --git a/src/lib/array.c b/src/lib/array.c index f0d0d124..1bba21a0 100644 --- a/src/lib/array.c +++ b/src/lib/array.c @@ -97,6 +97,16 @@ ANN void m_vector_rem(const M_Vector v, m_uint index) { } } +ANN void m_vector_insert(const M_Vector v, m_uint index, const void* data) { + const size_t size = ARRAY_SIZE(v); + if(++ARRAY_LEN(v) >= ARRAY_CAP(v)) { + const m_uint cap = ARRAY_CAP(v) *=2; + v->ptr = (m_bit*)xrealloc(v->ptr, ARRAY_OFFSET + cap * size); + } + memmove(ARRAY_PTR(v) + (index+1) * size, ARRAY_PTR(v) + index*size, (ARRAY_LEN(v) - index + 1)* size); + memcpy(ARRAY_PTR(v) + index*size, data, size); +} + static MFUN(vm_vector_rem) { const m_int index = *(m_int*)(shred->mem + SZ_INT); const M_Vector v = ARRAY(o); @@ -129,13 +139,7 @@ static MFUN(vm_vector_insert) { const M_Vector v = ARRAY(o); if(index < 0 || (m_uint)index > ARRAY_LEN(v)) return; - const size_t size = ARRAY_SIZE(v); - if(++ARRAY_LEN(v) >= ARRAY_CAP(v)) { - const m_uint cap = ARRAY_CAP(v) *=2; - v->ptr = (m_bit*)xrealloc(v->ptr, ARRAY_OFFSET + cap * size); - } - memmove(ARRAY_PTR(v) + (index+1) * size, ARRAY_PTR(v) + index*size, (ARRAY_LEN(v) - index + 1)* size); - memcpy(ARRAY_PTR(v) + index*size, shred->mem + SZ_INT*2, size); + m_vector_insert(v, index, shred->mem + SZ_INT*2); } static MFUN(vm_vector_insert_obj) { @@ -143,13 +147,7 @@ static MFUN(vm_vector_insert_obj) { const M_Vector v = ARRAY(o); if(index < 0 || (m_uint)index > ARRAY_LEN(v)) return; - const size_t size = SZ_INT; - if(++ARRAY_LEN(v) >= ARRAY_CAP(v)) { - const m_uint cap = ARRAY_CAP(v) *=2; - v->ptr = (m_bit*)xrealloc(v->ptr, ARRAY_OFFSET + cap * size); - } - memmove(ARRAY_PTR(v) + (index+1) *size, ARRAY_PTR(v) + index*size, (ARRAY_LEN(v) - index + 1)* size); - memcpy(ARRAY_PTR(v) + index*size, shred->mem + SZ_INT*2, size); + m_vector_insert(v, index, shred->mem + SZ_INT*2); ++(*(M_Object*)(shred->mem + SZ_INT*2))->ref; } @@ -158,13 +156,7 @@ static MFUN(vm_vector_insert_struct) { const M_Vector v = ARRAY(o); if(index < 0 || (m_uint)index > ARRAY_LEN(v)) return; - const size_t size = ARRAY_SIZE(v); - if(++ARRAY_LEN(v) >= ARRAY_CAP(v)) { - const m_uint cap = ARRAY_CAP(v) *=2; - v->ptr = (m_bit*)xrealloc(v->ptr, ARRAY_OFFSET + cap * size); - } - memmove(ARRAY_PTR(v) + (index+1) *size, ARRAY_PTR(v) + index*size, (ARRAY_LEN(v) - index + 1)* size); - memcpy(ARRAY_PTR(v) + index*size, shred->mem + SZ_INT*2, size); + m_vector_insert(v, index, shred->mem + SZ_INT*2); struct_addref(shred->info->vm->gwion, array_base(o->type_ref), shred->mem + SZ_INT*2); }