[svn:mod_parrot] r611 - in mod_parrot/trunk: include src

[email protected] Sun, 8 Feb 2009 09:40:49 -0800 (PST)
Newsgroups perl.cvs.mod_parrot
Message-ID <[email protected]>
Author: jhorwitz
Date: Sun Feb  8 09:40:48 2009
New Revision: 611

Modified:
   mod_parrot/trunk/include/mod_parrot.h
   mod_parrot/trunk/src/context.c
   mod_parrot/trunk/src/mod_parrot.c
   mod_parrot/trunk/src/module.c

Log:
store the context pool name in its first modparrot_context element. this avoids
costly scans in an external hash.


Modified: mod_parrot/trunk/include/mod_parrot.h
==============================================================================
--- mod_parrot/trunk/include/mod_parrot.h	(original)
+++ mod_parrot/trunk/include/mod_parrot.h	Sun Feb  8 09:40:48 2009
@@ -120,8 +120,9 @@
 apr_size_t modparrot_request_read(request_rec *, char *, apr_size_t);
 Parrot_PMC modparrot_wrap_apache_type(Parrot_Interp, char *, char *, void *);
 apr_array_header_t *modparrot_get_named_ctx_pool(const char *);
-void modparrot_set_named_ctx_pool(const char *, apr_array_header_t *);
-const char *modparrot_find_ctx_pool_name(apr_pool_t *, apr_array_header_t *);
+void modparrot_set_named_ctx_pool(apr_pool_t *p, const char *,
+    apr_array_header_t *);
+const char *modparrot_get_ctx_pool_name(apr_array_header_t *);
 
 /* macros for wrapping apache types */
 #define modparrot_wrap_apr_pool(i, x) \

Modified: mod_parrot/trunk/src/context.c
==============================================================================
--- mod_parrot/trunk/src/context.c	(original)
+++ mod_parrot/trunk/src/context.c	Sun Feb  8 09:40:48 2009
@@ -238,9 +238,13 @@
     apr_pool_userdata_set(ctxp, MP_KEY_CTX, modparrot_ctx_cleanup, p);
 }
 
-void modparrot_set_named_ctx_pool(const char *name, apr_array_header_t *cp)
+void modparrot_set_named_ctx_pool(apr_pool_t *p, const char *name,
+    apr_array_header_t *cp)
 {
     apr_hash_set(mp_globals.ctx_pool_hash, name, APR_HASH_KEY_STRING, cp);
+    /* we always have 1 valid context, so use it to store the pool name */
+    APR_ARRAY_IDX(cp, 0, modparrot_context *)->ctx_pool_name =
+        (const char *)apr_pstrdup(p, name);
 }
 
 apr_array_header_t *modparrot_get_named_ctx_pool(const char *name)
@@ -251,22 +255,8 @@
     return cp;
 }
 
-const char *modparrot_find_ctx_pool_name(apr_pool_t *p,
-    apr_array_header_t *ctx_pool)
+const char *modparrot_get_ctx_pool_name(apr_array_header_t *cp)
 {
-    apr_hash_index_t *idx;
-    char *name = NULL;
-
-    for (idx = apr_hash_first(p, mp_globals.ctx_pool_hash); idx;
-        idx = apr_hash_next(idx)) {
-        const void *key;
-        apr_ssize_t klen;
-        void *val;
-        apr_hash_this(idx, &key, &klen, &val);
-        if (val == ctx_pool) {
-            name = (char *)apr_pstrdup(p, (char *)key);
-            break;
-        }
-    }
-    return name;
+    /* we always have 1 valid context, so use it to retreive the pool name */
+    return APR_ARRAY_IDX(cp, 0, modparrot_context *)->ctx_pool_name;
 }

Modified: mod_parrot/trunk/src/mod_parrot.c
==============================================================================
--- mod_parrot/trunk/src/mod_parrot.c	(original)
+++ mod_parrot/trunk/src/mod_parrot.c	Sun Feb  8 09:40:48 2009
@@ -184,6 +184,7 @@
         cfg = ap_get_module_config(per_dir_config, modp);
         if (cfg) {
             if (cfg->ctx_pool) {
+                MP_TRACE_c(s, "select_ctx_pool: using section pool %p", cfg->ctx_pool);
                 return(cfg->ctx_pool);
             }
         }
@@ -193,11 +194,13 @@
     cfg = ap_get_module_config(s->module_config, modp);
     if (cfg) {
         if (cfg->ctx_pool) {
+            MP_TRACE_c(s, "select_ctx_pool: using server pool %p", cfg->ctx_pool);
             return(cfg->ctx_pool);
         }
     }
 
     /* fall back to the module's default pool */
+    MP_TRACE_c(s, "select_ctx_pool: using module default pool %p", minfo->ctx_pool);
     return(minfo->ctx_pool);
 }
 
@@ -307,7 +310,7 @@
             return NULL;
         }
         /* name the pool so we can reference it later */
-        modparrot_set_named_ctx_pool(name, ctx_pool);
+        modparrot_set_named_ctx_pool(p, name, ctx_pool);
         MP_TRACE_c(s, "modparrot_startup: context pool %p is named '%s'", ctx_pool, name);
 
         /* if server doesn't have a context pool, assign this one */

Modified: mod_parrot/trunk/src/module.c
==============================================================================
--- mod_parrot/trunk/src/module.c	(original)
+++ mod_parrot/trunk/src/module.c	Sun Feb  8 09:40:48 2009
@@ -210,9 +210,8 @@
 
     /* mod_parrot specific stuff */
     if (!minfo->ctx_pool_name) {
-        ctx_pool_name = modparrot_find_ctx_pool_name(cmd->pool,
-            minfo->ctx_pool);
-        minfo->ctx_pool_name = ctx_pool_name; /* assuming cmd->pool is ok */
+        ctx_pool_name = modparrot_get_ctx_pool_name(minfo->ctx_pool);
+        minfo->ctx_pool_name = ctx_pool_name;
     }
     else {
         ctx_pool_name = minfo->ctx_pool_name;