OSDN Git Service

* Optimization
authorAtsushi Konno <konn@users.sourceforge.jp>
Fri, 11 Mar 2011 05:35:22 +0000 (14:35 +0900)
committerAtsushi Konno <konn@users.sourceforge.jp>
Fri, 11 Mar 2011 05:35:22 +0000 (14:35 +0900)
    - apply_convrule is called in two or more useless times.

include/mod_chxj.h
src/chxj_cookie.c
src/chxj_encoding.c
src/chxj_img_conv_format.c
src/mod_chxj.c

index a5966b1..0eece78 100755 (executable)
@@ -380,9 +380,10 @@ struct mod_chxj_config {
 };
 
 struct mod_chxj_req_config_t {
-  char         *user_agent;
-  device_table *spec;
-  ap_filter_t  *f;
+  char               *user_agent;
+  device_table       *spec;
+  ap_filter_t        *f;
+  chxjconvrule_entry *entryp;
 };
 
 #define IS_COOKIE_STORE_DBM(X)      ((X) == COOKIE_STORE_TYPE_DBM)
index e90c79f..1753c36 100644 (file)
@@ -115,6 +115,7 @@ chxj_save_cookie(request_rec *r)
   char                *old_cookie_id;
   char                *store_string;
   mod_chxj_config     *dconf;
+  mod_chxj_req_config *req_conf;
   chxjconvrule_entry  *entryp;
   apr_table_t         *new_cookie_table;
   int                 has_cookie = 0;
@@ -137,7 +138,16 @@ chxj_save_cookie(request_rec *r)
   has_refer = 0;
 
   dconf = chxj_get_module_config(r->per_dir_config, &chxj_module);
-  entryp = chxj_apply_convrule(r, dconf->convrules);
+  req_conf = chxj_get_module_config(r->request_config, &chxj_module);
+  /*-------------------------------------------------------------------------*/
+  /* already setup entryp if request_conf->user_agent is not null            */
+  /*-------------------------------------------------------------------------*/
+  if (req_conf->user_agent) {
+    entryp = req_conf->entryp;
+  }
+  else {
+    entryp = chxj_apply_convrule(r, dconf->convrules);
+  }
   if (! entryp) {
     DBG(r,"REQ[%X] end %s() no pattern",TO_ADDR(r),__func__);
     return NULL;
@@ -351,6 +361,7 @@ chxj_update_cookie(request_rec *r, cookie_t *old_cookie)
   apr_table_entry_t   *hentryp;
   char                *store_string;
   mod_chxj_config     *dconf;
+  mod_chxj_req_config *req_conf;
   chxjconvrule_entry  *entryp;
   cookie_t            *cookie;
 
@@ -366,7 +377,16 @@ chxj_update_cookie(request_rec *r, cookie_t *old_cookie)
   cookie->cookie_id = NULL;
 
   dconf = chxj_get_module_config(r->per_dir_config, &chxj_module);
-  entryp = chxj_apply_convrule(r, dconf->convrules);
+  req_conf = chxj_get_module_config(r->request_config, &chxj_module);
+  /*-------------------------------------------------------------------------*/
+  /* already setup entryp if request_conf->user_agent is not null            */
+  /*-------------------------------------------------------------------------*/
+  if (req_conf->user_agent) {
+    entryp = req_conf->entryp;
+  }
+  else {
+    entryp = chxj_apply_convrule(r, dconf->convrules);
+  }
   if (! entryp) {
     DBG(r,"REQ[%X] no pattern",TO_ADDR(r));
     DBG(r,"REQ[%X] end %s()",TO_ADDR(r),__func__);
@@ -461,6 +481,7 @@ cookie_t *
 chxj_load_cookie(request_rec *r, char *cookie_id)
 {
   mod_chxj_config         *dconf;
+  mod_chxj_req_config     *req_conf;
   chxjconvrule_entry      *entryp;
   cookie_t                *cookie;
   apr_table_t             *load_cookie_table;
@@ -482,7 +503,16 @@ chxj_load_cookie(request_rec *r, char *cookie_id)
 
 
   dconf = chxj_get_module_config(r->per_dir_config, &chxj_module);
-  entryp = chxj_apply_convrule(r, dconf->convrules);
+  req_conf = chxj_get_module_config(r->request_config, &chxj_module);
+  /*-------------------------------------------------------------------------*/
+  /* already setup entryp if request_conf->user_agent is not null            */
+  /*-------------------------------------------------------------------------*/
+  if (req_conf->user_agent) {
+    entryp = req_conf->entryp;
+  }
+  else {
+    entryp = chxj_apply_convrule(r, dconf->convrules);
+  }
   if (! entryp) {
     DBG(r,"REQ[%X] pattern", TO_ADDR(r));
     DBG(r,"REQ[%X] end %s()",TO_ADDR(r),__func__);
index 79efb37..deb9a13 100644 (file)
@@ -35,6 +35,7 @@ chxj_encoding(request_rec *r, const char *src, apr_size_t *len)
   apr_size_t          ilen;
   apr_size_t          olen;
   mod_chxj_config     *dconf;
+  mod_chxj_req_config *req_conf;
   chxjconvrule_entry  *entryp;
   apr_pool_t          *pool;
 
@@ -54,7 +55,16 @@ chxj_encoding(request_rec *r, const char *src, apr_size_t *len)
     return (char *)apr_pstrdup(r->pool, "");
   }
 
-  entryp = chxj_apply_convrule(r, dconf->convrules);
+  req_conf = chxj_get_module_config(r->request_config, &chxj_module);
+  /*-------------------------------------------------------------------------*/
+  /* already setup entryp if request_conf->user_agent is not null            */
+  /*-------------------------------------------------------------------------*/
+  if (req_conf->user_agent) {
+    entryp = req_conf->entryp;
+  }
+  else {
+    entryp = chxj_apply_convrule(r, dconf->convrules);
+  }
   if (entryp->encoding == NULL) {
     DBG(r,"REQ[%X] none encoding.", TO_ADDR(r));
     DBG(r,"REQ[%X] end %s()",TO_ADDR(r),__func__);
@@ -252,6 +262,7 @@ chxj_rencoding(request_rec *r, const char *src, apr_size_t *len,const char *enc)
   apr_size_t          ilen;
   apr_size_t          olen;
   mod_chxj_config     *dconf;
+  mod_chxj_req_config *req_conf;
   chxjconvrule_entry  *entryp;
 
   DBG(r,"REQ[%X] start %s()",TO_ADDR(r),__func__);
@@ -269,7 +280,16 @@ chxj_rencoding(request_rec *r, const char *src, apr_size_t *len,const char *enc)
     return (char*)src;
   }
 
-  entryp = chxj_apply_convrule(r, dconf->convrules);
+  req_conf = chxj_get_module_config(r->request_config, &chxj_module);
+  /*-------------------------------------------------------------------------*/
+  /* already setup entryp if request_conf->user_agent is not null            */
+  /*-------------------------------------------------------------------------*/
+  if (req_conf->user_agent) {
+    entryp = req_conf->entryp;
+  }
+  else {
+    entryp = chxj_apply_convrule(r, dconf->convrules);
+  }
   if (! entryp->encoding) {
     DBG(r,"REQ[%X] none encoding.",TO_ADDR(r));
     DBG(r,"REQ[%X] end %s()",TO_ADDR(r),__func__);
index 85bc8a6..867e6d0 100644 (file)
@@ -249,6 +249,7 @@ int
 chxj_img_conv_format_handler(request_rec *r)
 {
   mod_chxj_config       *conf;
+  mod_chxj_req_config   *req_conf;
   query_string_param_t  *qsp;
   char                  *user_agent;
   device_table          *spec;
@@ -269,6 +270,7 @@ chxj_img_conv_format_handler(request_rec *r)
 
   qsp = s_get_query_string_param(r);
   conf = chxj_get_module_config(r->per_dir_config, &chxj_module);
+  req_conf = chxj_get_module_config(r->request_config, &chxj_module);
   if (conf == NULL) {
     DBG(r,"REQ[%X] conf is null",TO_ADDR(r));
     DBG(r,"REQ[%X] end %s()",TO_ADDR(r),__func__);
@@ -291,7 +293,15 @@ chxj_img_conv_format_handler(request_rec *r)
     user_agent = apr_pstrdup(r->pool, qsp->user_agent);
   }
   else {
-    entryp = chxj_apply_convrule(r, conf->convrules);
+    /*-------------------------------------------------------------------------*/
+    /* already setup entryp if request_conf->user_agent is not null            */
+    /*-------------------------------------------------------------------------*/
+    if (req_conf->user_agent) {
+      entryp = req_conf->entryp;
+    }
+    else {
+      entryp = chxj_apply_convrule(r, conf->convrules);
+    }
     if (entryp && entryp->user_agent) {
       user_agent = (char*)apr_table_get(r->headers_in, CHXJ_HTTP_USER_AGENT);
     }
@@ -305,14 +315,13 @@ chxj_img_conv_format_handler(request_rec *r)
   if (qsp->ua_flag == UA_IGN)
     spec = &v_ignore_spec;
   else {
-    mod_chxj_req_config *request_conf = chxj_get_module_config(r->request_config, &chxj_module);
-    if (request_conf->user_agent 
+    if (req_conf->user_agent 
         && user_agent 
-        && strcmp(request_conf->user_agent, user_agent) != 0) {
+        && strcmp(req_conf->user_agent, user_agent) != 0) {
       spec = chxj_specified_device(r, user_agent);
     }
     else {
-      spec = request_conf->spec;
+      spec = req_conf->spec;
     }
   }
 
@@ -366,6 +375,7 @@ chxj_convert_image(request_rec *r, const char **src, apr_size_t *len)
     return NULL;
   }
 
+  mod_chxj_req_config *req_conf = chxj_get_module_config(r->request_config, &chxj_module);
   /*--------------------------------------------------------------------------*/
   /* User-Agent to spec                                                       */
   /*--------------------------------------------------------------------------*/
@@ -373,7 +383,15 @@ chxj_convert_image(request_rec *r, const char **src, apr_size_t *len)
     user_agent = apr_pstrdup(r->pool, qsp->user_agent);
   }
   else {
-    entryp = chxj_apply_convrule(r, conf->convrules);
+    /*-------------------------------------------------------------------------*/
+    /* already setup entryp if request_conf->user_agent is not null            */
+    /*-------------------------------------------------------------------------*/
+    if (req_conf->user_agent) {
+      entryp = req_conf->entryp;
+    }
+    else {
+      entryp = chxj_apply_convrule(r, conf->convrules);
+    }
     if (entryp && entryp->user_agent) {
       user_agent = (char*)apr_table_get(r->headers_in, CHXJ_HTTP_USER_AGENT);
     }
@@ -385,14 +403,13 @@ chxj_convert_image(request_rec *r, const char **src, apr_size_t *len)
   if (qsp->ua_flag == UA_IGN)
     spec = &v_ignore_spec;
   else {
-    mod_chxj_req_config *request_conf = chxj_get_module_config(r->request_config, &chxj_module);
-    if (request_conf->user_agent
+    if (req_conf->user_agent
         && user_agent
-        && strcmp(request_conf->user_agent, user_agent) != 0) {
+        && strcmp(req_conf->user_agent, user_agent) != 0) {
       spec = chxj_specified_device(r, user_agent);
     }
     else {
-      spec = request_conf->spec;
+      spec = req_conf->spec;
     }
   }
 
index fa6cc88..efde57a 100644 (file)
@@ -192,9 +192,10 @@ chxj_headers_fixup(request_rec *r)
   request_conf = (mod_chxj_req_config *)chxj_get_module_config(r->request_config, &chxj_module);
   if (!request_conf) {
     request_conf = apr_palloc(r->pool, sizeof(mod_chxj_req_config));
-    request_conf->spec = NULL;
+    request_conf->spec       = NULL;
     request_conf->user_agent = NULL;
-    request_conf->f = NULL;
+    request_conf->f          = NULL;
+    request_conf->entryp     = NULL;
     chxj_set_module_config(r->request_config, &chxj_module, request_conf);
   }
   dconf = chxj_get_module_config(r->per_dir_config, &chxj_module);
@@ -228,7 +229,7 @@ chxj_headers_fixup(request_rec *r)
   case CHXJ_SPEC_Hdml:
   case CHXJ_SPEC_Jhtml:
   case CHXJ_SPEC_Jxhtml:
-    entryp = chxj_apply_convrule(r, dconf->convrules);
+    request_conf->entryp = entryp = chxj_apply_convrule(r, dconf->convrules);
     if (dconf->image != CHXJ_IMG_ON) {
       if (! entryp) {
         DBG(r, "REQ[%X] end %s() (no pattern)", TO_ADDR(r), __func__);
@@ -445,7 +446,15 @@ chxj_convert(request_rec *r, const char **src, apr_size_t *len, device_table *sp
   request_conf = chxj_get_module_config(r->request_config, &chxj_module);
 
 
-  entryp = chxj_apply_convrule(r, dconf->convrules);
+  /*-------------------------------------------------------------------------*/
+  /* already setup entryp if request_conf->user_agent is not null            */
+  /*-------------------------------------------------------------------------*/
+  if (request_conf->user_agent) {
+    entryp = request_conf->entryp;
+  }
+  else {
+    entryp = chxj_apply_convrule(r, dconf->convrules);
+  }
 
   if (!entryp 
       || (     !(entryp->action & CONVRULE_ENGINE_ON_BIT) 
@@ -1540,7 +1549,16 @@ chxj_input_handler(request_rec *r)
   else {
     spec = request_conf->spec;
   }
-  entryp = chxj_apply_convrule(r, dconf->convrules);
+
+  /*-------------------------------------------------------------------------*/
+  /* already setup entryp if request_conf->user_agent is not null            */
+  /*-------------------------------------------------------------------------*/
+  if (request_conf->user_agent) {
+    entryp = request_conf->entryp;
+  }
+  else {
+    entryp = chxj_apply_convrule(r, dconf->convrules);
+  }
 
   post_data = apr_pstrdup(pool, "");
   if (ap_setup_client_block(r, REQUEST_CHUNKED_DECHUNK) == OK) {
@@ -1790,7 +1808,16 @@ chxj_insert_filter(request_rec *r)
   else {
     spec = req_conf->spec;
   }
-  entryp = chxj_apply_convrule(r, dconf->convrules);
+  req_conf = chxj_get_module_config(r->request_config, &chxj_module);
+  /*-------------------------------------------------------------------------*/
+  /* already setup entryp if request_conf->user_agent is not null            */
+  /*-------------------------------------------------------------------------*/
+  if (req_conf->user_agent) {
+    entryp = req_conf->entryp;
+  }
+  else {
+    entryp = chxj_apply_convrule(r, dconf->convrules);
+  }
   if (!entryp && dconf->image != CHXJ_IMG_ON) {
     DBG(r, "REQ[%X] entryp is NULL and ChxjImageEngine Off", TO_ADDR(r));
     DBG(r, "REQ[%X] end %s()", TO_ADDR(r),__func__);