make ngx_pool clear2

liuyujun liuyujun at fingera.cn
Tue Jun 4 08:38:21 UTC 2019


hello. everybody here?

example before:
    for (p = pool; p; p = p->d.next) {
        p->d.last = (u_char *) p + sizeof(ngx_pool_t);
        p->d.failed = 0;
    }




after:
    for (p = &pool->d; p; p = p->next) {
        if (p == &pool->d) {
            p->last = (u_char *) p + sizeof(ngx_pool_t);
        } else {
            p->last = (u_char *) p + sizeof(ngx_pool_data_t);
        }
        p->failed = 0;
    }




example2 before:
static void *
ngx_palloc_block(ngx_pool_t *pool, size_t size)
{
    u_char      *m;
    size_t       psize;
    ngx_pool_t  *p, *new;

    psize = (size_t) (pool->d.end - (u_char *) pool);

    m = ngx_memalign(NGX_POOL_ALIGNMENT, psize, pool->log);
    if (m == NULL) {
        return NULL;
    }

    new = (ngx_pool_t *) m;

    new->d.end = m + psize;
    new->d.next = NULL;
    new->d.failed = 0;

    m += sizeof(ngx_pool_data_t);
    m = ngx_align_ptr(m, NGX_ALIGNMENT);
    new->d.last = m + size;

    for (p = pool->current; p->d.next; p = p->d.next) {
        if (p->d.failed++ > 4) {
            pool->current = p->d.next;
        }
    }

    p->d.next = new;

    return m;
}


after:
static void *
ngx_palloc_block(ngx_pool_t *pool, size_t size)
{
    u_char           *m;
    size_t            psize;
    ngx_pool_data_t  *p, *new;

    psize = (size_t) (pool->d.end - (u_char *) pool);

    m = ngx_memalign(NGX_POOL_ALIGNMENT, psize, pool->log);
    if (m == NULL) {
        return NULL;
    }

    new = (ngx_pool_data_t *) m;

    new->end = m + psize;
    new->next = NULL;
    new->failed = 0;

    m += sizeof(ngx_pool_data_t);
    m = ngx_align_ptr(m, NGX_ALIGNMENT);
    new->last = m + size;

    for (p = pool->current; p->next; p = p->next) {
        if (p->failed++ > 4) {
            pool->current = p->next;
        }
    }

    p->next = new;

    return m;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx/attachments/20190604/58953f20/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: diff.patch
Type: application/octet-stream
Size: 4301 bytes
Desc: not available
URL: <http://mailman.nginx.org/pipermail/nginx/attachments/20190604/58953f20/attachment-0001.obj>


More information about the nginx mailing list