diff options
author | Lucas De Marchi <lucas.demarchi@intel.com> | 2014-10-16 21:39:33 -0300 |
---|---|---|
committer | Lucas De Marchi <lucas.demarchi@intel.com> | 2014-10-16 21:39:33 -0300 |
commit | e62d8c725b73cc03efc01df59bf5cc5a5fa31b5d (patch) | |
tree | a46c84200601b45f3598cdb6a0d64bdd32a681d4 /shared | |
parent | 8863154e446d6b60ff6afd6572ce5d9c9651a59c (diff) | |
download | kmod-e62d8c725b73cc03efc01df59bf5cc5a5fa31b5d.tar.gz kmod-e62d8c725b73cc03efc01df59bf5cc5a5fa31b5d.tar.bz2 kmod-e62d8c725b73cc03efc01df59bf5cc5a5fa31b5d.zip |
strbuf: make strbuf_pushchars() a little less dumb
Do not push one char at a time. We have strlen() and memcpy() to rely
on.
Diffstat (limited to 'shared')
-rw-r--r-- | shared/strbuf.c | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/shared/strbuf.c b/shared/strbuf.c index af445d9..e5df35d 100644 --- a/shared/strbuf.c +++ b/shared/strbuf.c @@ -22,6 +22,7 @@ #include <assert.h> #include <stdbool.h> #include <stdlib.h> +#include <string.h> #include "util.h" #include "strbuf.h" @@ -93,15 +94,20 @@ bool strbuf_pushchar(struct strbuf *buf, char ch) unsigned strbuf_pushchars(struct strbuf *buf, const char *str) { - unsigned i = 0; - int ch; + unsigned int len; - while ((ch = str[i])) { - strbuf_pushchar(buf, ch); - i++; - } + assert(str != NULL); + assert(buf != NULL); + + len = strlen(str); + + if (!buf_grow(buf, buf->used + len)) + return 0; + + memcpy(buf->bytes + buf->used, str, len); + buf->used += len; - return i; + return len; } void strbuf_popchar(struct strbuf *buf) |