aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2014-04-09 22:50:28 -0700
committerChris Robinson <[email protected]>2014-04-09 22:50:28 -0700
commit90ae4b7c0f675e0a0846af376f6025ccfd8f7bc9 (patch)
treed9db59c53037cf91753dca6193cec536d0f8a8e3
parent023981acb9242649f1fff8b02143a26e85005a9f (diff)
Add a VECTOR_INSERT method to insert a range of elements at once
-rw-r--r--Alc/helpers.c20
-rw-r--r--Alc/midi/sf2load.c16
-rw-r--r--Alc/vector.h3
3 files changed, 29 insertions, 10 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);
diff --git a/Alc/midi/sf2load.c b/Alc/midi/sf2load.c
index 1c7cc10b..91e68d7d 100644
--- a/Alc/midi/sf2load.c
+++ b/Alc/midi/sf2load.c
@@ -346,20 +346,16 @@ static void GenModList_Destruct(GenModList *self)
static GenModList GenModList_clone(const GenModList *self)
{
- ALsizei count, i;
GenModList ret;
GenModList_Construct(&ret);
- count = VECTOR_SIZE(self->gens);
- VECTOR_RESERVE(ret.gens, count);
- for(i = 0;i < count;i++)
- VECTOR_PUSH_BACK(ret.gens, VECTOR_ELEM(self->gens, i));
-
- count = VECTOR_SIZE(self->mods);
- VECTOR_RESERVE(ret.mods, count);
- for(i = 0;i < count;i++)
- VECTOR_PUSH_BACK(ret.mods, VECTOR_ELEM(self->mods, i));
+ VECTOR_INSERT(ret.gens, VECTOR_ITER_END(ret.gens),
+ VECTOR_ITER_BEGIN(self->gens), VECTOR_ITER_END(self->gens)
+ );
+ VECTOR_INSERT(ret.mods, VECTOR_ITER_END(ret.mods),
+ VECTOR_ITER_BEGIN(self->mods), VECTOR_ITER_END(self->mods)
+ );
return ret;
}
diff --git a/Alc/vector.h b/Alc/vector.h
index 57939719..2993aac5 100644
--- a/Alc/vector.h
+++ b/Alc/vector.h
@@ -35,6 +35,9 @@ ALboolean vector_resize(void *ptr, size_t base_size, size_t obj_count, size_t ob
#define VECTOR_ITER_BEGIN(_x) ((_x)->Data)
#define VECTOR_ITER_END(_x) ((_x)->Data + VECTOR_SIZE((_x)))
+ALboolean vector_insert(void *ptr, size_t base_size, size_t obj_size, ptrdiff_t ins_elem, const void *datstart, ptrdiff_t numins);
+#define VECTOR_INSERT(_x, _i, _s, _e) (vector_insert(&(_x), sizeof(*(_x)), sizeof((_x)->Data[0]), (_i)-VECTOR_ITER_BEGIN(_x), (_s), (_e)-(_s)))
+
#define VECTOR_PUSH_BACK(_x, _obj) (vector_reserve(&(_x), sizeof(*(_x)), VECTOR_SIZE(_x)+1, sizeof((_x)->Data[0]), AL_FALSE) && \
(((_x)->Data[(_x)->Size++] = (_obj)),AL_TRUE))
#define VECTOR_POP_BACK(_x) ((void)((_x)->Size--))