speed up ngx_http_charset_recode() for 25%: google-perftools reported

that CPU usage of charset body filter has decreased from 7.5% to 5.5%
if gzipping is disabled
This commit is contained in:
Igor Sysoev 2008-03-16 16:52:15 +00:00
parent 70d0961658
commit 430db103f6

View File

@ -561,27 +561,35 @@ ngx_http_charset_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
static ngx_uint_t static ngx_uint_t
ngx_http_charset_recode(ngx_buf_t *b, u_char *table) ngx_http_charset_recode(ngx_buf_t *b, u_char *table)
{ {
u_char *p; u_char *p, *last;
for (p = b->pos; p < b->last; p++) { last = b->last;
if (*p == table[*p]) { for (p = b->pos; p < last; p++) {
continue;
if (*p != table[*p]) {
goto recode;
}
} }
while (p < b->last) { return 0;
recode:
do {
if (*p != table[*p]) {
*p = table[*p]; *p = table[*p];
p++;
} }
p++;
} while (p < last);
b->in_file = 0; b->in_file = 0;
return 1; return 1;
} }
return 0;
}
static ngx_chain_t * static ngx_chain_t *
ngx_http_charset_recode_from_utf8(ngx_pool_t *pool, ngx_buf_t *buf, ngx_http_charset_recode_from_utf8(ngx_pool_t *pool, ngx_buf_t *buf,