From a762d3dcab2a87b9b60f32a19f2d40c871422edd Mon Sep 17 00:00:00 2001 From: Michael Koloberdin Date: Tue, 12 May 2009 03:22:46 +0100 Subject: [PATCH 2/2] Optimized mod_redirect_patch_connection(). --- src/mod_redirect.c | 38 ++++++++++++++++++++++---------------- 1 files changed, 22 insertions(+), 16 deletions(-) diff --git a/src/mod_redirect.c b/src/mod_redirect.c index 4963d6c..df6b5db 100644 --- a/src/mod_redirect.c +++ b/src/mod_redirect.c @@ -15,9 +15,11 @@ typedef struct { pcre_keyvalue_buffer *redirect; + int redirect_defined; #ifdef HAVE_GLIB_H GHashTable *redirect_simple; #endif + int redirect_simple_defined; data_config *context; /* to which apply me */ unsigned short redirect_code; @@ -112,7 +114,9 @@ SETDEFAULTS_FUNC(mod_redirect_set_defaults) { s = calloc(1, sizeof(plugin_config)); s->redirect = pcre_keyvalue_buffer_init(); +#ifdef HAVE_GLIB_H s->redirect_simple = g_hash_table_new(buffer_key_hash, buffer_key_equal); +#endif cv[0].destination = s->redirect; cv[1].destination = s->redirect_simple; @@ -127,6 +131,7 @@ SETDEFAULTS_FUNC(mod_redirect_set_defaults) { if (NULL != (du = array_get_element(ca, CONST_STR_LEN("url.redirect")))) { /* url.redirect defined */ + s->redirect_defined = 1; if (du->type != TYPE_ARRAY) { log_error_write(srv, __FILE__, __LINE__, "sss", "unexpected type for key: ", "url.redirect", "array of strings"); @@ -155,8 +160,10 @@ SETDEFAULTS_FUNC(mod_redirect_set_defaults) { } } } +#ifdef HAVE_GLIB_H if (NULL != (du = array_get_element(ca, CONST_STR_LEN("url.redirect-simple")))) { /* url.redirect-simple defined */ + s->redirect_simple_defined = 1; if (du->type != TYPE_ARRAY) { log_error_write(srv, __FILE__, __LINE__, "sss", "unexpected type for key: ", "url.redirect-simple", "array of strings"); @@ -186,13 +193,14 @@ SETDEFAULTS_FUNC(mod_redirect_set_defaults) { ); } } +#endif } return HANDLER_GO_ON; } #if defined (HAVE_PCRE_H) || defined (HAVE_GLIB_H) static int mod_redirect_patch_connection(server *srv, connection *con, plugin_data *p) { - size_t i, j; + size_t i; plugin_config *s = p->config_storage[0]; #ifdef HAVE_PCRE_H @@ -208,29 +216,27 @@ static int mod_redirect_patch_connection(server *srv, connection *con, plugin_da data_config *dc = (data_config *)srv->config_context->data[i]; s = p->config_storage[i]; + /* do not bother to check the condition if nothing defined in this context */ + if (!s->redirect_defined && !s->redirect_simple_defined) continue; + /* condition didn't match */ if (!config_check_cond(srv, con, dc)) continue; /* merge config */ - for (j = 0; j < dc->value->used; j++) { - data_unset *du = dc->value->data[j]; - - if #ifdef HAVE_PCRE_H - (buffer_is_equal_string(du->key, CONST_STR_LEN("url.redirect"))) { - PATCH_OPTION(redirect); - p->conf.context = dc; - } else if + if (s->redirect_defined) { + PATCH_OPTION(redirect); + p->conf.context = dc; + } #endif #ifdef HAVE_GLIB_H - (buffer_is_equal_string(du->key, CONST_STR_LEN("url.redirect-simple"))) { - PATCH_OPTION(redirect_simple); - p->conf.context = dc; - } else if + if (s->redirect_simple_defined) { + PATCH_OPTION(redirect_simple); + p->conf.context = dc; + } #endif - (buffer_is_equal_string(du->key, CONST_STR_LEN("url.redirect-code"))) { - PATCH_OPTION(redirect_code); - } + if (s->redirect_code) { + PATCH_OPTION(redirect_code); } } -- 1.6.2.5