Hello,
I don’t understand why b->last is used to initialize b->end.
Why it’s not :
b->end = b->start + size;
Regards,
yves
HG changeset patch
Date 1407480933 -7200
Node ID 74265a0edba677c967f532de789a4589436aa5fb
Parent a62fffc16af816612a4acf34c7a4781f454fa5d1
ngx_buf: initialize b->end with b->start
diff -r a62fffc16af8 -r 74265a0edba6 src/core/ngx_buf.c
— a/src/core/ngx_buf.c Fri Aug 08 08:45:23 2014 +0200
+++ b/src/core/ngx_buf.c Fri Aug 08 08:55:33 2014 +0200
@@ -37,7 +37,7 @@
b->pos = b->start;
b->last = b->start;
Posted at Nginx Forum:
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
- 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 D.
http://nginx.org/