Welcome! Log In Create A New Profile

Advanced

Re: optimize the code for searching file in ngx_conf_open_file

Maxim Dounin
October 07, 2023 02:00PM
Hello!

On Sat, Oct 07, 2023 at 06:09:18AM +0200, Davood Falahati wrote:

> # 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];
> }
> }

Thanks for your efforts, but we prefer the code as is.

There is no difference between these variants from the performance
point of view. On the other hand, the existing variant with
separate length comparison is certainly more readable. Further,
the suggested change uses incorrect indentation, which is just
wrong.

For more information about submitting patches, please see tips
here:

http://nginx.org/en/docs/contributing_changes.html

For more information about nginx coding style, please refer to the
code and here:

http://nginx.org/en/docs/dev/development_guide.html#code_style

Hope this helps.

--
Maxim Dounin
http://mdounin.ru/
_______________________________________________
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 226 October 07, 2023 12:10AM

Re: optimize the code for searching file in ngx_conf_open_file

Maxim Dounin 72 October 07, 2023 02:00PM



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

Online Users

Guests: 297
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