[nginx] Sub filter: switched to ngx_chain_get_free_buf().

Maxim Dounin mdounin at mdounin.ru
Thu Jul 25 11:58:37 UTC 2013


details:   http://hg.nginx.org/nginx/rev/d47ef93134e5
branches:  
changeset: 5285:d47ef93134e5
user:      Maxim Dounin <mdounin at mdounin.ru>
date:      Thu Jul 25 14:54:45 2013 +0400
description:
Sub filter: switched to ngx_chain_get_free_buf().

No functional changes.

diffstat:

 src/http/modules/ngx_http_sub_filter_module.c |  83 +++++++-------------------
 1 files changed, 22 insertions(+), 61 deletions(-)

diffs (139 lines):

diff --git a/src/http/modules/ngx_http_sub_filter_module.c b/src/http/modules/ngx_http_sub_filter_module.c
--- a/src/http/modules/ngx_http_sub_filter_module.c
+++ b/src/http/modules/ngx_http_sub_filter_module.c
@@ -268,25 +268,14 @@ ngx_http_sub_body_filter(ngx_http_reques
 
                 if (ctx->saved.len) {
 
-                    if (ctx->free) {
-                        cl = ctx->free;
-                        ctx->free = ctx->free->next;
-                        b = cl->buf;
-                        ngx_memzero(b, sizeof(ngx_buf_t));
+                    cl = ngx_chain_get_free_buf(r->pool, &ctx->free);
+                    if (cl == NULL) {
+                        return NGX_ERROR;
+                    }
 
-                    } else {
-                        b = ngx_calloc_buf(r->pool);
-                        if (b == NULL) {
-                            return NGX_ERROR;
-                        }
+                    b = cl->buf;
 
-                        cl = ngx_alloc_chain_link(r->pool);
-                        if (cl == NULL) {
-                            return NGX_ERROR;
-                        }
-
-                        cl->buf = b;
-                    }
+                    ngx_memzero(b, sizeof(ngx_buf_t));
 
                     b->pos = ngx_pnalloc(r->pool, ctx->saved.len);
                     if (b->pos == NULL) {
@@ -303,24 +292,12 @@ ngx_http_sub_body_filter(ngx_http_reques
                     ctx->saved.len = 0;
                 }
 
-                if (ctx->free) {
-                    cl = ctx->free;
-                    ctx->free = ctx->free->next;
-                    b = cl->buf;
+                cl = ngx_chain_get_free_buf(r->pool, &ctx->free);
+                if (cl == NULL) {
+                    return NGX_ERROR;
+                }
 
-                } else {
-                    b = ngx_alloc_buf(r->pool);
-                    if (b == NULL) {
-                        return NGX_ERROR;
-                    }
-
-                    cl = ngx_alloc_chain_link(r->pool);
-                    if (cl == NULL) {
-                        return NGX_ERROR;
-                    }
-
-                    cl->buf = b;
-                }
+                b = cl->buf;
 
                 ngx_memcpy(b, ctx->buf, sizeof(ngx_buf_t));
 
@@ -335,7 +312,6 @@ ngx_http_sub_body_filter(ngx_http_reques
                     b->file_pos += b->pos - ctx->buf->pos;
                 }
 
-                cl->next = NULL;
                 *ctx->last_out = cl;
                 ctx->last_out = &cl->next;
             }
@@ -356,15 +332,14 @@ ngx_http_sub_body_filter(ngx_http_reques
 
             /* rc == NGX_OK */
 
-            b = ngx_calloc_buf(r->pool);
-            if (b == NULL) {
+            cl = ngx_chain_get_free_buf(r->pool, &ctx->free);
+            if (cl == NULL) {
                 return NGX_ERROR;
             }
 
-            cl = ngx_alloc_chain_link(r->pool);
-            if (cl == NULL) {
-                return NGX_ERROR;
-            }
+            b = cl->buf;
+
+            ngx_memzero(b, sizeof(ngx_buf_t));
 
             slcf = ngx_http_get_module_loc_conf(r, ngx_http_sub_filter_module);
 
@@ -386,8 +361,6 @@ ngx_http_sub_body_filter(ngx_http_reques
                 b->sync = 1;
             }
 
-            cl->buf = b;
-            cl->next = NULL;
             *ctx->last_out = cl;
             ctx->last_out = &cl->next;
 
@@ -398,29 +371,17 @@ ngx_http_sub_body_filter(ngx_http_reques
 
         if (ctx->buf->last_buf || ngx_buf_in_memory(ctx->buf)) {
             if (b == NULL) {
-                if (ctx->free) {
-                    cl = ctx->free;
-                    ctx->free = ctx->free->next;
-                    b = cl->buf;
-                    ngx_memzero(b, sizeof(ngx_buf_t));
+                cl = ngx_chain_get_free_buf(r->pool, &ctx->free);
+                if (cl == NULL) {
+                    return NGX_ERROR;
+                }
 
-                } else {
-                    b = ngx_calloc_buf(r->pool);
-                    if (b == NULL) {
-                        return NGX_ERROR;
-                    }
+                b = cl->buf;
 
-                    cl = ngx_alloc_chain_link(r->pool);
-                    if (cl == NULL) {
-                        return NGX_ERROR;
-                    }
-
-                    cl->buf = b;
-                }
+                ngx_memzero(b, sizeof(ngx_buf_t));
 
                 b->sync = 1;
 
-                cl->next = NULL;
                 *ctx->last_out = cl;
                 ctx->last_out = &cl->next;
             }



More information about the nginx-devel mailing list