]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: Optimize str_append_n()
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Sat, 30 Apr 2016 11:05:42 +0000 (14:05 +0300)
committerGitLab <gitlab@git.dovecot.net>
Tue, 3 May 2016 16:49:03 +0000 (19:49 +0300)
src/lib/str.c

index 6e6066839ecf093242c1f52064e7ace71d8cec00..3a5c92dd06f1ecb35bb27bf8ce0d0be1288af0c5 100644 (file)
@@ -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);
 }