# HG changeset patch # User Igor Sysoev # Date 1205686335 0 # Node ID be6c9033a79872f7ef50c35b5526180390482b19 # Parent 5acc8bea2c49644b7adf01363accc14ac6994a8a 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 diff --git a/src/http/modules/ngx_http_charset_filter_module.c b/src/http/modules/ngx_http_charset_filter_module.c --- a/src/http/modules/ngx_http_charset_filter_module.c +++ b/src/http/modules/ngx_http_charset_filter_module.c @@ -561,25 +561,33 @@ ngx_http_charset_body_filter(ngx_http_re static ngx_uint_t ngx_http_charset_recode(ngx_buf_t *b, u_char *table) { - u_char *p; - - for (p = b->pos; p < b->last; p++) { + u_char *p, *last; - if (*p == table[*p]) { - continue; - } + last = b->last; - while (p < b->last) { - *p = table[*p]; - p++; + for (p = b->pos; p < last; p++) { + + if (*p != table[*p]) { + goto recode; } - - b->in_file = 0; - - return 1; } return 0; + +recode: + + do { + if (*p != table[*p]) { + *p = table[*p]; + } + + p++; + + } while (p < last); + + b->in_file = 0; + + return 1; }