[PATCH v6 15/15] Static: optimize "index" iteration

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


Iterate over "index" only if "share" is a directory.

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 | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/src/nxt_http_static.c b/src/nxt_http_static.c
index d6bb88d..74245cd 100644
--- a/src/nxt_http_static.c
+++ b/src/nxt_http_static.c
@@ -713,7 +713,10 @@ nxt_http_static_next(nxt_task_t *task, nxt_http_request_t *r,
     action = ctx->action;
     conf = action->u.conf;
 
-    ctx->index_idx = (ctx->index_idx + 1) % conf->nindices;
+    if (ctx->share.start[ctx->share.length - 1] == '/') {
+        ctx->index_idx = (ctx->index_idx + 1) % conf->nindices;
+    }
+
     if (ctx->index_idx == 0) {
         ctx->share_idx++;
     }
-- 
2.34.1



More information about the unit mailing list