changeset 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 5acc8bea2c49
children ab18958e1322
files src/http/modules/ngx_http_charset_filter_module.c
diffstat 1 files changed, 21 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- 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;
 }