Improve efficiency of m_3cat() algorithm

Use exact memcpy() instead of repeated strcat().
This commit is contained in:
Kevin Easton
2019-12-28 17:30:01 +11:00
parent 4f63d48929
commit eaf6456854

View File

@@ -274,27 +274,27 @@ char *BX_m_s3cat_s (char **one, const char *maybe, const char *ifthere)
char *BX_m_3cat(char **one, const char *two, const char *three) char *BX_m_3cat(char **one, const char *two, const char *three)
{ {
int len = 0; size_t one_len = 0, two_len = 0, three_len = 0;
char *str; char *str;
if (*one) if (*one)
len = strlen(*one); one_len = strlen(*one);
if (two) if (two)
len += strlen(two); two_len = strlen(two);
if (three) if (three)
len += strlen(three); three_len = strlen(three);
len += 1;
str = (char *)new_malloc(len); str = new_malloc(one_len + two_len + three_len + 1);
if (*one) if (*one)
strcpy(str, *one); memcpy(str, *one, one_len);
if (two) if (two)
strcat(str, two); memcpy(str + one_len, two, two_len);
if (three) if (three)
strcat(str, three); memcpy(str + one_len + two_len, three, three_len);
str[one_len + two_len + three_len] = 0;
new_free(one); new_free(one);
return ((*one = str)); return (*one = str);
} }
/* upper() /* upper()