comparison src/http/modules/ngx_http_charset_filter_module.c @ 1944:be6c9033a798

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
author Igor Sysoev <igor@sysoev.ru>
date Sun, 16 Mar 2008 16:52:15 +0000
parents 8f8e0a60685f
children c0bafb136d7b
comparison
equal deleted inserted replaced
1943:5acc8bea2c49 1944:be6c9033a798
559 559
560 560
561 static ngx_uint_t 561 static ngx_uint_t
562 ngx_http_charset_recode(ngx_buf_t *b, u_char *table) 562 ngx_http_charset_recode(ngx_buf_t *b, u_char *table)
563 { 563 {
564 u_char *p; 564 u_char *p, *last;
565 565
566 for (p = b->pos; p < b->last; p++) { 566 last = b->last;
567 567
568 if (*p == table[*p]) { 568 for (p = b->pos; p < last; p++) {
569 continue; 569
570 } 570 if (*p != table[*p]) {
571 571 goto recode;
572 while (p < b->last) { 572 }
573 }
574
575 return 0;
576
577 recode:
578
579 do {
580 if (*p != table[*p]) {
573 *p = table[*p]; 581 *p = table[*p];
574 p++; 582 }
575 } 583
576 584 p++;
577 b->in_file = 0; 585
578 586 } while (p < last);
579 return 1; 587
580 } 588 b->in_file = 0;
581 589
582 return 0; 590 return 1;
583 } 591 }
584 592
585 593
586 static ngx_chain_t * 594 static ngx_chain_t *
587 ngx_http_charset_recode_from_utf8(ngx_pool_t *pool, ngx_buf_t *buf, 595 ngx_http_charset_recode_from_utf8(ngx_pool_t *pool, ngx_buf_t *buf,