summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorMaxim Dounin <mdounin@mdounin.ru>2013-07-25 14:54:45 +0400
committerMaxim Dounin <mdounin@mdounin.ru>2013-07-25 14:54:45 +0400
commit8d568c7ae01d5bcf566d64ae89622ee67810bb28 (patch)
treef8eb2b665324e64cd89fb8c83e840d4244f15da7
parent3961ef2318a21254f928147198b7909967f1cddb (diff)
downloadnginx-8d568c7ae01d5bcf566d64ae89622ee67810bb28.tar.gz
nginx-8d568c7ae01d5bcf566d64ae89622ee67810bb28.tar.bz2
Sub filter: switched to ngx_chain_get_free_buf().
No functional changes.
-rw-r--r--src/http/modules/ngx_http_sub_filter_module.c85
1 files changed, 23 insertions, 62 deletions
diff --git a/src/http/modules/ngx_http_sub_filter_module.c b/src/http/modules/ngx_http_sub_filter_module.c
index 37b04256b..6a14dbdc2 100644
--- a/src/http/modules/ngx_http_sub_filter_module.c
+++ b/src/http/modules/ngx_http_sub_filter_module.c
@@ -268,26 +268,15 @@ ngx_http_sub_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
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));
-
- } else {
- b = ngx_calloc_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;
+ cl = ngx_chain_get_free_buf(r->pool, &ctx->free);
+ if (cl == NULL) {
+ return NGX_ERROR;
}
+ b = cl->buf;
+
+ ngx_memzero(b, sizeof(ngx_buf_t));
+
b->pos = ngx_pnalloc(r->pool, ctx->saved.len);
if (b->pos == NULL) {
return NGX_ERROR;
@@ -303,25 +292,13 @@ ngx_http_sub_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
ctx->saved.len = 0;
}
- if (ctx->free) {
- cl = ctx->free;
- ctx->free = ctx->free->next;
- b = cl->buf;
-
- } 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;
+ cl = ngx_chain_get_free_buf(r->pool, &ctx->free);
+ if (cl == NULL) {
+ return NGX_ERROR;
}
+ b = cl->buf;
+
ngx_memcpy(b, ctx->buf, sizeof(ngx_buf_t));
b->pos = ctx->copy_start;
@@ -335,7 +312,6 @@ ngx_http_sub_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
b->file_pos += b->pos - ctx->buf->pos;
}
- cl->next = NULL;
*ctx->last_out = cl;
ctx->last_out = &cl->next;
}
@@ -356,16 +332,15 @@ ngx_http_sub_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
/* rc == NGX_OK */
- b = ngx_calloc_buf(r->pool);
- if (b == NULL) {
- return NGX_ERROR;
- }
-
- cl = ngx_alloc_chain_link(r->pool);
+ cl = ngx_chain_get_free_buf(r->pool, &ctx->free);
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);
if (ctx->sub.data == NULL) {
@@ -386,8 +361,6 @@ ngx_http_sub_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
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_request_t *r, ngx_chain_t *in)
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));
-
- } else {
- b = ngx_calloc_buf(r->pool);
- if (b == NULL) {
- return NGX_ERROR;
- }
+ 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;
- 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;
}