Skip to content

Commit

Permalink
lib: Optimize str_append_n()
Browse files Browse the repository at this point in the history
  • Loading branch information
sirainen authored and GitLab committed May 3, 2016
1 parent 53e9cbd commit 88bcf81
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/lib/str.c
Expand Up @@ -83,12 +83,14 @@ bool str_equals(const string_t *str1, const string_t *str2)

void str_append_n(string_t *str, const void *cstr, size_t max_len)
{
const char *p;
size_t len;

len = 0;
while (len < max_len && ((const char *)cstr)[len] != '\0')
len++;

p = memchr(cstr, '\0', max_len);
if (p == NULL)
len = max_len;
else
len = p - (const char *)cstr;
buffer_append(str, cstr, len);
}

Expand Down

0 comments on commit 88bcf81

Please sign in to comment.