summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2014-04-13 17:06:18 -0700
committerChris Robinson <[email protected]>2014-04-13 17:06:18 -0700
commitcce9609b9ec69f8d139cee139d79ec01c9e2b533 (patch)
tree52fa5379fa412ad7c567c440cd492c3a773069b9
parente76bc53d3724463f5375d303e13f385875f596e6 (diff)
Avoid referencing the start iterator twice for vector insertion
-rw-r--r--Alc/helpers.c5
-rw-r--r--Alc/vector.h4
2 files changed, 5 insertions, 4 deletions
diff --git a/Alc/helpers.c b/Alc/helpers.c
index 7607493e..2fbb588b 100644
--- a/Alc/helpers.c
+++ b/Alc/helpers.c
@@ -796,11 +796,12 @@ 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)
+ALboolean vector_insert(void *ptr, size_t base_size, size_t obj_size, ptrdiff_t ins_elem, const void *datstart, const void *datend)
{
vector_ *vecptr = ptr;
- if(*vecptr || numins > 0)
+ if(datstart != datend)
{
+ ptrdiff_t numins = ((const char*)datend - (const char*)datstart) / obj_size;
if(!vector_reserve(vecptr, base_size, VECTOR_SIZE(*vecptr)+numins, obj_size, AL_TRUE))
return AL_FALSE;
if(ins_elem < (*vecptr)->Size)
diff --git a/Alc/vector.h b/Alc/vector.h
index 2993aac5..7f3d769c 100644
--- a/Alc/vector.h
+++ b/Alc/vector.h
@@ -35,8 +35,8 @@ 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)))
+ALboolean vector_insert(void *ptr, size_t base_size, size_t obj_size, ptrdiff_t ins_elem, const void *datstart, const void *datend);
+#define VECTOR_INSERT(_x, _i, _s, _e) (vector_insert(&(_x), sizeof(*(_x)), sizeof((_x)->Data[0]), (_i)-VECTOR_ITER_BEGIN(_x), (_s), (_e)))
#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))