diff options
author | Chris Robinson <[email protected]> | 2014-04-09 22:50:28 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2014-04-09 22:50:28 -0700 |
commit | 90ae4b7c0f675e0a0846af376f6025ccfd8f7bc9 (patch) | |
tree | d9db59c53037cf91753dca6193cec536d0f8a8e3 /Alc/helpers.c | |
parent | 023981acb9242649f1fff8b02143a26e85005a9f (diff) |
Add a VECTOR_INSERT method to insert a range of elements at once
Diffstat (limited to 'Alc/helpers.c')
-rw-r--r-- | Alc/helpers.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/Alc/helpers.c b/Alc/helpers.c index 2845e056..7607493e 100644 --- a/Alc/helpers.c +++ b/Alc/helpers.c @@ -796,6 +796,26 @@ ALboolean vector_resize(void *ptr, size_t base_size, size_t obj_count, size_t ob return AL_TRUE; } +ALboolean vector_insert(void *ptr, size_t base_size, size_t obj_size, ptrdiff_t ins_elem, const void *datstart, ptrdiff_t numins) +{ + vector_ *vecptr = ptr; + if(*vecptr || numins > 0) + { + if(!vector_reserve(vecptr, base_size, VECTOR_SIZE(*vecptr)+numins, obj_size, AL_TRUE)) + return AL_FALSE; + if(ins_elem < (*vecptr)->Size) + { + memmove((char*)(*vecptr) + base_size + ((ins_elem+numins)*obj_size), + (char*)(*vecptr) + base_size + ((ins_elem )*obj_size), + ((*vecptr)->Size-ins_elem)*obj_size); + } + memcpy((char*)(*vecptr) + base_size + (ins_elem*obj_size), + datstart, numins*obj_size); + (*vecptr)->Size += (ALsizei)numins; + } + return AL_TRUE; +} + extern inline ALsizei al_string_length(const_al_string str); extern inline ALsizei al_string_empty(const_al_string str); |