diff options
author | Glenn Strauss <gstrauss@gluelogic.com> | 2021-06-08 22:57:36 -0400 |
---|---|---|
committer | Glenn Strauss <gstrauss@gluelogic.com> | 2021-08-27 02:16:53 -0400 |
commit | af3df29ae8276f4380ed25262bcdf3d95446a9b1 (patch) | |
tree | 2606d798d156da68dbcfc3f68a3c8d03490dfa11 /src/mod_rrdtool.c | |
parent | 937d83b6cf8b732b2acae13919a8d944542acd9c (diff) | |
download | lighttpd-git-af3df29ae8276f4380ed25262bcdf3d95446a9b1.tar.gz |
[multiple] reduce redundant NULL buffer checks
This commit is a large set of code changes and results in removal of
hundreds, perhaps thousands, of CPU instructions, a portion of which
are on hot code paths.
Most (buffer *) used by lighttpd are not NULL, especially since buffers
were inlined into numerous larger structs such as request_st and chunk.
In the small number of instances where that is not the case, a NULL
check is often performed earlier in a function where that buffer is
later used with a buffer_* func. In the handful of cases that remained,
a NULL check was added, e.g. with r->http_host and r->conf.server_tag.
- check for empty strings at config time and set value to NULL if blank
string will be ignored at runtime; at runtime, simple pointer check
for NULL can be used to check for a value that has been set and is not
blank ("")
- use buffer_is_blank() instead of buffer_string_is_empty(),
and use buffer_is_unset() instead of buffer_is_empty(),
where buffer is known not to be NULL so that NULL check can be skipped
- use buffer_clen() instead of buffer_string_length() when buffer is
known not to be NULL (to avoid NULL check at runtime)
- use buffer_truncate() instead of buffer_string_set_length() to
truncate string, and use buffer_extend() to extend
Examples where buffer known not to be NULL:
- cpv->v.b from config_plugin_values_init is not NULL if T_CONFIG_BOOL
(though we might set it to NULL if buffer_is_blank(cpv->v.b))
- address of buffer is arg (&foo)
(compiler optimizer detects this in most, but not all, cases)
- buffer is checked for NULL earlier in func
- buffer is accessed in same scope without a NULL check (e.g. b->ptr)
internal behavior change:
callers must not pass a NULL buffer to some funcs.
- buffer_init_buffer() requires non-null args
- buffer_copy_buffer() requires non-null args
- buffer_append_string_buffer() requires non-null args
- buffer_string_space() requires non-null arg
Diffstat (limited to 'src/mod_rrdtool.c')
-rw-r--r-- | src/mod_rrdtool.c | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/src/mod_rrdtool.c b/src/mod_rrdtool.c index 45017697..ea65b933 100644 --- a/src/mod_rrdtool.c +++ b/src/mod_rrdtool.c @@ -186,7 +186,7 @@ SETDEFAULTS_FUNC(mod_rrd_set_defaults) { for (; -1 != cpv->k_id; ++cpv) { switch (cpv->k_id) { case 0: /* rrdtool.db-name */ - if (!buffer_string_is_empty(cpv->v.b)) { + if (!buffer_is_blank(cpv->v.b)) { rrd_config *rrd = calloc(1, sizeof(rrd_config)); force_assert(rrd); rrd->path_rrd = cpv->v.b; @@ -196,7 +196,7 @@ SETDEFAULTS_FUNC(mod_rrd_set_defaults) { } break; case 1: /* rrdtool.binary */ /* T_CONFIG_SCOPE_SERVER */ - if (!buffer_string_is_empty(cpv->v.b)) + if (!buffer_is_blank(cpv->v.b)) p->path_rrdtool_bin = cpv->v.b; /*(store directly in p)*/ break; default:/* should not happen */ @@ -279,7 +279,7 @@ static int mod_rrdtool_create_rrd(server *srv, plugin_data *p, rrd_config *s, ch buffer_clear(cmd); buffer_append_str3(cmd, CONST_STR_LEN("create "), - CONST_BUF_LEN(s->path_rrd), + BUF_PTR_LEN(s->path_rrd), CONST_STR_LEN( " --step 60 " "DS:InOctets:ABSOLUTE:600:U:U " @@ -298,7 +298,7 @@ static int mod_rrdtool_create_rrd(server *srv, plugin_data *p, rrd_config *s, ch "RRA:MIN:0.5:24:775 " "RRA:MIN:0.5:288:797\n")); - if (-1 == (safe_write(p->write_fd, CONST_BUF_LEN(cmd)))) { + if (-1 == (safe_write(p->write_fd, BUF_PTR_LEN(cmd)))) { log_perror(srv->errh, __FILE__, __LINE__, "rrdtool-write: failed"); return HANDLER_ERROR; } @@ -334,7 +334,7 @@ static int mod_rrd_write_data(server *srv, plugin_data *p, rrd_config *s) { buffer * const cmd = srv->tmp_buf; buffer_clear(cmd); buffer_append_str3(cmd, CONST_STR_LEN("update "), - CONST_BUF_LEN(s->path_rrd), + BUF_PTR_LEN(s->path_rrd), CONST_STR_LEN(" N:")); buffer_append_int(cmd, s->bytes_read); buffer_append_string_len(cmd, CONST_STR_LEN(":")); @@ -343,7 +343,7 @@ static int mod_rrd_write_data(server *srv, plugin_data *p, rrd_config *s) { buffer_append_int(cmd, s->requests); buffer_append_string_len(cmd, CONST_STR_LEN("\n")); - if (-1 == safe_write(p->write_fd, CONST_BUF_LEN(cmd))) { + if (-1 == safe_write(p->write_fd, BUF_PTR_LEN(cmd))) { log_error(srv->errh, __FILE__, __LINE__, "rrdtool-write: failed"); return mod_rrd_fatal_error(p); } |