Initialize ngx_buf_t in ngx_create_temp_buf()

Maxim Dounin mdounin at mdounin.ru
Fri Aug 8 12:58:03 UTC 2014


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/



More information about the nginx mailing list