Welcome! Log In Create A New Profile

Advanced

Re: question on some simple codes in ngx_buf.c

Maxim Dounin
January 16, 2014 11:52AM
Hello!

On Thu, Jan 16, 2014 at 02:04:45AM -0500, microwish wrote:

> Hello there,
>
> code snippet in the definition of ngx_chain_add_copy in ngx_buf.c:
>
>
> ll = chain;
>
>
>
> for (cl = *chain; cl; cl = cl->next) {
> ll = &cl->next;
> }
>
>
> Why is ll assigned repeatedly? I'm sorry for failed thinking out any
> necessity.
>
> And I modified the above as the following. Is it OK?
>
>
> if (*chain) {
> for (cl = *chain; cl->next; cl = cl->next) { /* void */ }
> ll = &cl->next;
> } else {
> ll = chain;
> }
>
>
> Thank you very much.

The code snippets look equivalent from logical point of view.
From performance point of view - they are mostly equivalent too,
as cl->next address anyway needs to be loaded on each cycle
iteration and will be available in a register, so assignment is
essentially a nop. The code currently used is shorter though, and
easier to read.

--
Maxim Dounin
http://nginx.org/

_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Subject Author Posted

question on some simple codes in ngx_buf.c

microwish January 16, 2014 02:04AM

Re: question on some simple codes in ngx_buf.c

Maxim Dounin January 16, 2014 11:52AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

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