Welcome! Log In Create A New Profile

Advanced

optimize the code for searching file in ngx_conf_open_file

Davood Falahati
October 07, 2023 12:10AM
# HG changeset patch
# User Davood Falahati <0x0davood@gmail.com>
# Date 1696647746 -7200
# Sat Oct 07 05:02:26 2023 +0200
# Node ID ab14ea51bbb15331c9f44f14901d0fd378168647
# Parent c073e545e1cdcc736f8869a012a78b2dd836eac9
optimize the code for searching file in ngx_conf_open_file

This patch combines two consecutive if statements into one and leveraging
short circuits circuiting. In the current code, we check the lengths of
file names and if they match, the file names are being compared.

I see few other places in the code that writing multiple if statements are
preferred over short circuit evaluation (e.g.
http://hg.nginx.org/nginx/file/tip/src/http/ngx_http_file_cache.c#l1153). I
wanted to make sure if it's a matter of community's taste or if it's in
line with some performance considerations?

diff -r c073e545e1cd -r ab14ea51bbb1 src/core/ngx_conf_file.c
--- a/src/core/ngx_conf_file.c Thu May 18 23:42:22 2023 +0200
+++ b/src/core/ngx_conf_file.c Sat Oct 07 05:02:26 2023 +0200
@@ -927,11 +927,7 @@
i = 0;
}

- if (full.len != file[i].name.len) {
- continue;
- }
-
- if (ngx_strcmp(full.data, file[i].name.data) == 0) {
+ if (full.len == file[i].name.len && ngx_strcmp(full.data,
file[i].name.data) == 0) {
return &file[i];
}
}
_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
https://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

optimize the code for searching file in ngx_conf_open_file

Davood Falahati 254 October 07, 2023 12:10AM

Re: optimize the code for searching file in ngx_conf_open_file

Maxim Dounin 88 October 07, 2023 02:00PM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 87
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready