[PATCH v4 13/13] Static: optimize "index" iteration

Alejandro Colomar alx.manpages at gmail.com
Thu Dec 23 20:14:56 UTC 2021


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>
---
 src/nxt_http_static.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/src/nxt_http_static.c b/src/nxt_http_static.c
index 30b7fd6..50f63b2 100644
--- a/src/nxt_http_static.c
+++ b/src/nxt_http_static.c
@@ -711,7 +711,13 @@ 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;
+
+    } else {
+        ctx->index_idx = 0;
+    }
+
     if (ctx->index_idx == 0) {
         ctx->share_idx++;
     }
-- 
2.34.1



More information about the unit mailing list