Commit ed7aec77 authored by Rusty Russell's avatar Rusty Russell

str_talloc: make strjoin much more efficient.

Inspired by patch from Volker.
parent 377395cf
......@@ -38,11 +38,17 @@ char *strjoin(const void *ctx, char *strings[], const char *delim)
{
unsigned int i;
char *ret = talloc_strdup(ctx, "");
size_t totlen = 0, dlen = strlen(delim);
for (i = 0; strings[i]; i++) {
ret = talloc_append_string(ret, strings[i]);
ret = talloc_append_string(ret, delim);
size_t len = strlen(strings[i]);
ret = talloc_realloc(ctx, ret, char, totlen + len + dlen + 1);
memcpy(ret + totlen, strings[i], len);
totlen += len;
memcpy(ret + totlen, delim, dlen);
totlen += dlen;
}
ret[totlen] = '\0';
return ret;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment