[PATCH v6 13/15] nxt_http_static_init(): Simplify branching

Alejandro Colomar alx.manpages at gmail.com
Tue Feb 15 14:57:53 UTC 2022


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>
Cc: Andrei Zeliankou <zelenkov at nginx.com>
Cc: Maxim Romanov <m.romanov 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 bee85b2..cbc8cbf 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