Welcome! Log In Create A New Profile

Advanced

Re: Initialize ngx_buf_t in ngx_create_temp_buf()

Maxim Dounin
August 08, 2014 09:00AM
Hello!

On Fri, Aug 08, 2014 at 02:56:12AM -0400, crespin wrote:

> Hello,
>
> I don't understand why b->last is used to initialize b->end.
> Why it's not :
> b->end = b->start + size;

There is no real difference, though current code produces 1 less
assembly instruction at least on gcc 4.2 with -O1 / -O2:

.loc 1 39 0
movl %eax, 4(%ebx)
.loc 1 40 0
- addl 12(%ebp), %eax
+ movl 12(%ebp), %eax
+ addl 24(%ebx), %eax
movl %eax, 28(%ebx)
.loc 1 41 0
orb $1, 44(%ebx)

There is no difference in code generated by gcc 4.9, as expected.

Quick look shows that the code dates back to the most recent
snapshot available, and at that time it just used the matching
value which was set last:

h->pre_start = ngx_palloc(pool, size + before + after);
h->start = h->pos.p = h->last.p = h->pre_start + before;
h->end = h->last.p + size;
h->post_end = h->end + after;

Since then the code was simplified, but using of the value that is
set last seems to be still slightly beneficial in some cases.

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

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

Initialize ngx_buf_t in ngx_create_temp_buf()

crespin August 08, 2014 02:56AM

Re: Initialize ngx_buf_t in ngx_create_temp_buf()

Maxim Dounin August 08, 2014 09:00AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

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