aboutsummaryrefslogtreecommitdiffstats
path: root/Alc/helpers.c
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2014-04-13 20:54:12 -0700
committerChris Robinson <[email protected]>2014-04-13 20:54:12 -0700
commite615ea3cf951849e9ff5e1812492b418b02de409 (patch)
tree491a75ec568d3c672bb62a5f8d9a311363a7beca /Alc/helpers.c
parent219a0e6352c27c1fec52bebd4eccfddbc2813737 (diff)
Use VECTOR_INSERT to copy and append strings
Diffstat (limited to 'Alc/helpers.c')
-rw-r--r--Alc/helpers.c20
1 files changed, 8 insertions, 12 deletions
diff --git a/Alc/helpers.c b/Alc/helpers.c
index 97f7988e..1ad5abe9 100644
--- a/Alc/helpers.c
+++ b/Alc/helpers.c
@@ -861,9 +861,8 @@ void al_string_copy(al_string *str, const_al_string from)
{
ALsizei len = VECTOR_SIZE(from);
VECTOR_RESERVE(*str, len+1);
- VECTOR_RESIZE(*str, len);
- memcpy(&VECTOR_FRONT(*str), &VECTOR_FRONT(from),
- len*sizeof(al_string_char_type));
+ VECTOR_RESIZE(*str, 0);
+ VECTOR_INSERT(*str, VECTOR_ITER_END(*str), VECTOR_ITER_BEGIN(from), VECTOR_ITER_BEGIN(from)+len);
*VECTOR_ITER_END(*str) = 0;
}
@@ -871,8 +870,8 @@ void al_string_copy_cstr(al_string *str, const al_string_char_type *from)
{
size_t len = strlen(from);
VECTOR_RESERVE(*str, len+1);
- VECTOR_RESIZE(*str, len);
- memcpy(&VECTOR_FRONT(*str), from, len*sizeof(al_string_char_type));
+ VECTOR_RESIZE(*str, 0);
+ VECTOR_INSERT(*str, VECTOR_ITER_END(*str), from, from+len);
*VECTOR_ITER_END(*str) = 0;
}
@@ -889,20 +888,17 @@ void al_string_append_cstr(al_string *str, const al_string_char_type *from)
if(len != 0)
{
VECTOR_RESERVE(*str, al_string_length(*str)+len+1);
- VECTOR_RESIZE(*str, al_string_length(*str)+len);
- memcpy(VECTOR_ITER_END(*str)-len, from, len);
+ VECTOR_INSERT(*str, VECTOR_ITER_END(*str), from, from+len);
*VECTOR_ITER_END(*str) = 0;
}
}
void al_string_append_range(al_string *str, const al_string_char_type *from, const al_string_char_type *to)
{
- ptrdiff_t len = to - from;
- if(len != 0)
+ if(to != from)
{
- VECTOR_RESERVE(*str, al_string_length(*str)+len+1);
- VECTOR_RESIZE(*str, al_string_length(*str)+len);
- memcpy(VECTOR_ITER_END(*str)-len, from, len);
+ VECTOR_RESERVE(*str, al_string_length(*str)+(to-from)+1);
+ VECTOR_INSERT(*str, VECTOR_ITER_END(*str), from, to);
*VECTOR_ITER_END(*str) = 0;
}
}