httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dmitry Khrustalev <d...@bog.msu.su>
Subject Re: misc profiling comments
Date Sun, 11 Jan 1998 11:19:05 GMT


On Sat, 10 Jan 1998, Dean Gaudet wrote:

> invoke_handler, interesting...  I bet you we could short-circuit this with
> a config-time pass through the table to build a tree or something.  It is
> constant after config-time.

Here is what i use:

--- /usr/local/apache/ap/apachen/src/main/http_config.c	Sat Jan 10 18:38:43 1998
+++ http_config.c	Sun Jan 11 13:48:59 1998
@@ -413,58 +413,91 @@
     return run_method(r, offsets_into_method_ptrs.auth_checker, 0);
 }
 
-int invoke_handler(request_rec *r)
-{
-    module *modp;
-    handler_rec *handp;
-    char *content_type = r->content_type ? r->content_type : default_type(r);
-    char *handler, *p;
-
-    if ((p = strchr(content_type, ';')) != NULL) {	/* MIME type arguments */
-	while (p > content_type && p[-1] == ' ')
-	    --p;		/* strip trailing spaces */
-	content_type = pstrndup(r->pool, content_type, p - content_type);
-    }
-    handler = r->handler ? r->handler : content_type;
+static handler_rec *handlers;
+static handler_rec *wildhandlers;
 
-    /* Pass one --- direct matches */
+static void init_handlers(pool *p) {
+    module *modp;
+    int nhandlers = 0;
+    int nwildhandlers = 0;
+    handler_rec *handp, *ph, *pw;
+    char *ct;
 
     for (modp = top_module; modp; modp = modp->next) {
 	if (!modp->handlers)
 	    continue;
-
 	for (handp = modp->handlers; handp->content_type; ++handp) {
-	    if (!strcasecmp(handler, handp->content_type)) {
-		int result = (*handp->handler) (r);
-
-		if (result != DECLINED)
-		    return result;
-	    }
-	}
+	    if (strchr(handp->content_type, '*')) {
+                nwildhandlers ++;
+            } else {
+                nhandlers ++;
+            }
+        }
     }
-
-    /* Pass two --- wildcard matches */
-
+    ph = handlers = palloc(p, sizeof(handler_rec)*(nhandlers + 1));
+    pw = wildhandlers = palloc(p, sizeof(handler_rec)*(nwildhandlers + 1));
     for (modp = top_module; modp; modp = modp->next) {
 	if (!modp->handlers)
 	    continue;
-
 	for (handp = modp->handlers; handp->content_type; ++handp) {
-	    char *starp = strchr(handp->content_type, '*');
-	    int len;
+            ct = pstrdup(p, handp->content_type);
+            str_tolower(ct);
+	    if (strchr(handp->content_type, '*')) {
+                pw->content_type = ct;
+                pw->handler = handp->handler;
+                pw ++;
+            } else {
+                ph->content_type = ct;
+                ph->handler = handp->handler;
+                ph ++;
+            }
+        }
+    }
+    pw->content_type = NULL;
+    pw->handler = NULL;
+    ph->content_type = NULL;
+    ph->handler = NULL;
+}
 
-	    if (!starp)
-		continue;
+int invoke_handler(request_rec *r)
+{
+    handler_rec *handp;
+    char *content_type = pstrdup(r->pool, r->content_type ? r->content_type : default_type(r));
+    char *handler, *p;
 
-	    len = starp - handp->content_type;
+    if ((p = strchr(content_type, ';')) != NULL) { /* MIME type arguments */
+	while (p > content_type && p[-1] == ' ')
+	    --p;		/* strip trailing spaces */
+        p[0] = '\0';
+    }
+    handler = r->handler ? pstrdup(r->pool, r->handler) : content_type;
+    str_tolower(handler);
 
-	    if (!len || !strncasecmp(handler, handp->content_type, len)) {
-		int result = (*handp->handler) (r);
+    /* Pass one --- direct matches */
 
-		if (result != DECLINED)
-		    return result;
-	    }
-	}
+    for (handp = handlers; handp->content_type; ++handp) {
+        if (!strcmp(handler, handp->content_type)) {
+            int result = (*handp->handler) (r);
+
+            if (result != DECLINED)
+                return result;
+        }
+    }
+
+    /* Pass two --- wildcard matches */
+
+    for (handp = wildhandlers; handp->content_type; ++handp) {
+         char *starp = strchr(handp->content_type, '*');
+         int len;
+
+         len = starp - handp->content_type;
+
+         if (!len || !strncmp(handler, handp->content_type, len)) {
+             int result = (*handp->handler) (r);
+
+             if (result != DECLINED)
+                 return result;
+         }
     }
 
     return NOT_IMPLEMENTED;
@@ -1212,6 +1245,7 @@
     for (m = top_module; m; m = m->next)
 	if (m->init)
 	    (*m->init) (s, p);
+    init_handlers(p);
 }
 
 void child_init_modules(pool *p, server_rec *s)



Mime
View raw message