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

Alejandro Colomar alx.manpages at gmail.com
Fri Dec 24 12:20:01 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>
---

v5:
- Remove unnecessary 'else' (reported by Valentin)
- Only patch 13/13 is changed; patches v4 01..12/12 still apply.


 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 30b7fd6..28ec592 100644
--- a/src/nxt_http_static.c
+++ b/src/nxt_http_static.c
@@ -711,7 +711,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