[PATCH v3 11/12] nxt_http_static_init(): Simplify branching
Alejandro Colomar
alx.manpages at gmail.com
Sun Dec 19 01:30:29 UTC 2021
Add a bit of code to the special case of no "index", so that the
normal case is not in a branch. This makes the normal flow more
readable, by hiding details of special cases in branches, even if
that means making the special case a bit more complex than it
needs to be. 'else' distracts the mental parser of the reader of
the code: it means it needs to branch in both cases.
Signed-off-by: Alejandro Colomar <alx.manpages at gmail.com>
Cc: Nginx Unit <unit at nginx.org>
Cc: "Valentin V. Bartenev" <vbart at nginx.com>
Cc: Zhidao HONG <z.hong at f5.com>
Cc: Igor Sysoev <igor at sysoev.ru>
Cc: Oisin Canty <o.canty at f5.com>
---
src/nxt_http_static.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/src/nxt_http_static.c b/src/nxt_http_static.c
index 57d8ca8..16744f2 100644
--- a/src/nxt_http_static.c
+++ b/src/nxt_http_static.c
@@ -115,12 +115,16 @@ nxt_http_static_init(nxt_task_t *task, nxt_router_temp_conf_t *tmcf,
}
if (acf->index == NULL) {
- str = default_index;
+ acf->index = nxt_conf_create_object(mp, 1);
+ if (nxt_slow_path(acf->index == NULL)) {
+ return NXT_ERROR;
+ }
- } else {
- nxt_conf_get_string(acf->index, &str);
+ nxt_conf_set_string_dup(acf->index, mp, &default_index);
}
+ nxt_conf_get_string(acf->index, &str);
+
var = nxt_var_compile(&str, mp, 1);
if (nxt_slow_path(var == NULL)) {
return NXT_ERROR;
--
2.34.1
More information about the unit
mailing list