diff options
author | Glenn Strauss <gstrauss@gluelogic.com> | 2018-10-07 23:35:07 -0400 |
---|---|---|
committer | Glenn Strauss <gstrauss@gluelogic.com> | 2018-10-07 23:47:56 -0400 |
commit | f1489b5a113d94ac17c6e9b7b1fb8690f32b616a (patch) | |
tree | 75cb4b18852e4dd13a8c7c3308e2554f4dec8d07 /src/buffer.c | |
parent | 78d4ef9e0fae59b87d27cb1fad3b3e3cca51230b (diff) | |
download | lighttpd-git-f1489b5a113d94ac17c6e9b7b1fb8690f32b616a.tar.gz |
[core] perf: buffer.c internal inlines
buffer_copy_string_len() and buffer_append_string_len() now
internally inline what buffer_commit() does, but do not repeat the
sanity checks already enforced by buffer_string_prepare_copy() and
buffer_string_prepare_append(), respectively
buffer_string_set_length() short-circuit common case
Diffstat (limited to 'src/buffer.c')
-rw-r--r-- | src/buffer.c | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/src/buffer.c b/src/buffer.c index 32155600..d742cc63 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -145,9 +145,11 @@ char* buffer_string_prepare_append(buffer *b, size_t size) { void buffer_string_set_length(buffer *b, size_t len) { force_assert(NULL != b); - force_assert(len + 1 > len); - buffer_realloc(b, len + 1); + if (len >= b->size) { + force_assert(len + 1 > len); + buffer_realloc(b, len + 1); + } b->used = len + 1; b->ptr[len] = '\0'; @@ -181,9 +183,9 @@ void buffer_copy_string_len(buffer *b, const char *s, size_t s_len) { buffer_string_prepare_copy(b, s_len); - if (0 != s_len) memcpy(b->ptr, s, s_len); - - buffer_commit(b, s_len); + if (0 != s_len) memcpy(b->ptr, s, s_len); /*(s might be NULL)*/ + b->ptr[s_len] = '\0'; + b->used = s_len + 1; } void buffer_copy_buffer(buffer *b, const buffer *src) { @@ -218,11 +220,11 @@ void buffer_append_string_len(buffer *b, const char *s, size_t s_len) { target_buf = buffer_string_prepare_append(b, s_len); - if (0 == s_len) return; /* nothing to append */ + if (0 == s_len) return; /* nothing to append *//*(s might be NULL)*/ memcpy(target_buf, s, s_len); - - buffer_commit(b, s_len); + target_buf[s_len] = '\0'; + b->used += s_len; } void buffer_append_string_buffer(buffer *b, const buffer *src) { |