Opened 4 years ago
Closed 4 years ago
#1721 closed enhancement (fixed)
One line redundant code in ngx_slab_free_locked
|Reported by:||Owned by:|
|nginx -V:||nginx version: nginx/1.15.8|
Hi, When I read the source code of Nginx, I notice there is one line redundant code in ngx_slab_free_locked.
n = ((u_char *) p - pool->start) >> ngx_pagesize_shift;
In the beginning of this function, 'n' has been calculated, but in the case NGX_SLAB_PAGE, it is calculated again.
Please see the patch, thanks.
Change History (5)
by , 4 years ago
comment:1 by , 4 years ago
comment:2 by , 4 years ago
I think this is a better patch, thanks.
comment:3 by , 4 years ago
comment:4 by , 4 years ago
|Status:||new → closed|
Note: See TracTickets for help on using tickets.
nvariable is used in the following
&pool->pages[n]reference, and using generic multi-purpose variables in the parts of code distant from the code where it is calculated is generally a bad idea. Even if in a particular moment the variable stays intact, it can be overwritten at some point later, breaking things.
On the other hand, calculating
&pool->pages[n]looks unneeded too, as we already have
pagepointer. It should be fine to simply use
pageinstead of re-calculating it. Please test if the following patch works for you: