dgaudet     98/03/12 23:49:21

  Modified:    src/main http_config.c
               src      CHANGES
  Log:
  Another 2% improvement that's been queued waiting for the lowercase
  issues to be resolved.  This is "NULL-compression" for invoke_handler()
  similar to what happened in run_method() ages ago.  This helps the
  server scale when more modules are added.
  
  Submitted by:   Dmitry Khrustalev <[EMAIL PROTECTED]>
  
  Oh yeah and some CHANGES cleanup.
  
  Revision  Changes    Path
  1.103     +88 -37    apache-1.3/src/main/http_config.c
  
  Index: http_config.c
  ===================================================================
  RCS file: /export/home/cvs/apache-1.3/src/main/http_config.c,v
  retrieving revision 1.102
  retrieving revision 1.103
  diff -u -r1.102 -r1.103
  --- http_config.c     1998/03/12 12:11:13     1.102
  +++ http_config.c     1998/03/13 07:49:17     1.103
  @@ -413,58 +413,109 @@
       return run_method(r, offsets_into_method_ptrs.auth_checker, 0);
   }
   
  -int invoke_handler(request_rec *r)
  +/*
  + * For speed/efficiency we generate a compact list of all the handlers
  + * and wildcard handlers.  This means we won't have to scan the entire
  + * module list looking for handlers... where we'll find a whole whack
  + * of NULLs.
  + */
  +typedef struct {
  +    handler_rec hr;
  +    size_t len;
  +} fast_handler_rec;
  +
  +static fast_handler_rec *handlers;
  +static fast_handler_rec *wildhandlers;
  +
  +static void init_handlers(pool *p)
   {
       module *modp;
  +    int nhandlers = 0;
  +    int nwildhandlers = 0;
       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;
  -
  -    /* Pass one --- direct matches */
  +    fast_handler_rec *ph, *pw;
  +    char *starp;
   
       for (modp = top_module; modp; modp = modp->next) {
        if (!modp->handlers)
            continue;
  -
        for (handp = modp->handlers; handp->content_type; ++handp) {
  -         if (!strcmp(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(*ph)*(nhandlers + 1));
  +    pw = wildhandlers = palloc(p, sizeof(*pw)*(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;
  +         if ((starp = strchr(handp->content_type, '*'))) {
  +                pw->hr.content_type = handp->content_type;
  +                pw->hr.handler = handp->handler;
  +             pw->len = starp - handp->content_type;
  +                pw ++;
  +            } else {
  +                ph->hr.content_type = handp->content_type;
  +                ph->hr.handler = handp->handler;
  +             ph->len = strlen(handp->content_type);
  +                ph ++;
  +            }
  +        }
  +    }
  +    pw->hr.content_type = NULL;
  +    pw->hr.handler = NULL;
  +    ph->hr.content_type = NULL;
  +    ph->hr.handler = NULL;
  +}
   
  -         if (!starp)
  -             continue;
  +int invoke_handler(request_rec *r)
  +{
  +    fast_handler_rec *handp;
  +    char *handler, *p;
  +    size_t handler_len;
   
  -         len = starp - handp->content_type;
  +    if (r->handler) {
  +     handler = r->handler;
  +     handler_len = strlen(handler);
  +    }
  +    else {
  +     handler = r->content_type ? r->content_type : default_type(r);
  +     if ((p = strchr(handler, ';')) != NULL) { /* MIME type arguments */
  +         while (p > handler && p[-1] == ' ')
  +             --p;            /* strip trailing spaces */
  +         handler_len = p - handler;
  +     }
  +     else {
  +         handler_len = strlen(handler);
  +     }
  +    }
   
  -         if (!len || !strncmp(handler, handp->content_type, len)) {
  -             int result = (*handp->handler) (r);
  +    /* Pass one --- direct matches */
   
  -             if (result != DECLINED)
  -                 return result;
  -         }
  -     }
  +    for (handp = handlers; handp->hr.content_type; ++handp) {
  +     if (handler_len == handp->len
  +         && !strncmp(handler, handp->hr.content_type, handler_len)) {
  +            int result = (*handp->hr.handler) (r);
  +
  +            if (result != DECLINED)
  +                return result;
  +        }
  +    }
  +
  +    /* Pass two --- wildcard matches */
  +
  +    for (handp = wildhandlers; handp->hr.content_type; ++handp) {
  +     if (handler_len >= handp->len
  +         && !strncmp(handler, handp->hr.content_type, handp->len)) {
  +             int result = (*handp->hr.handler) (r);
  +
  +             if (result != DECLINED)
  +                 return result;
  +         }
       }
   
       return NOT_IMPLEMENTED;
  @@ -526,8 +577,6 @@
        m->name = tmp;
       }
   #endif /*_OSD_POSIX*/
  -/** XXX: this will be slow if there's lots of add_modules */
  -    build_method_shortcuts();
   }
   
   /* 
  @@ -1356,6 +1405,8 @@
       for (m = top_module; m; m = m->next)
        if (m->init)
            (*m->init) (s, p);
  +    build_method_shortcuts();
  +    init_handlers(p);
   }
   
   void child_init_modules(pool *p, server_rec *s)
  
  
  
  1.703     +42 -37    apache-1.3/src/CHANGES
  
  Index: CHANGES
  ===================================================================
  RCS file: /export/home/cvs/apache-1.3/src/CHANGES,v
  retrieving revision 1.702
  retrieving revision 1.703
  diff -u -r1.702 -r1.703
  --- CHANGES   1998/03/13 07:27:53     1.702
  +++ CHANGES   1998/03/13 07:49:19     1.703
  @@ -1,5 +1,8 @@
   Changes with Apache 1.3b6
   
  +  *) Performance improvements to invoke_handler().
  +     [Dmitry Khrustalev <[EMAIL PROTECTED]>]
  +
     *) Added support for building shared objects even for library-style modules
        (which are build from more than one object file). This now provides the
        ability to build mod_proxy as a shared object module. Additionally
  @@ -163,7 +166,7 @@
     *) Add the `%a' construct to LogFormat and CustomLog to log the client IP
        address. [Todd Eigenschink <[EMAIL PROTECTED]>, PR#1885]
   
  -  *) A new source module main/util_uri.c; It contains a routine
  +  *) API: A new source module main/util_uri.c; It contains a routine
        parse_uri_components() and friends which breaks a URI into its component
        parts.  These parts are stored in a uri_components structure called
        parsed_uri within each request_rec, and are available to all modules.
  @@ -274,8 +277,8 @@
     *) ap_cpystrn() had an off-by-1 error.
        [Charles Fu <[EMAIL PROTECTED]>] PR#1847
   
  -  *) As Ken suggested the check_cmd_context() function and related defines
  -     are non-static now so modules can use 'em.  [Martin Kraemer]
  +  *) API: As Ken suggested the check_cmd_context() function and related
  +     defines are non-static now so modules can use 'em.  [Martin Kraemer]
   
     *) mod_info would occasionally produce an unpaired <tt> in its
        output. Fixed. [Martin Kraemer]
  @@ -309,7 +312,7 @@
   
     *) Removed bogus "dist.tar" target from Makefile.tmpl and make sure
        backup files are removed on "clean" target [Ralf S. Engelschall]
  -     
  +
     *) PORT: Add -lm to LIBS for HPUX.  [Dean Gaudet] PR#1639
   
     *) Various errors from select() and accept() in child_main() would
  @@ -369,22 +372,22 @@
        (like mod_dld for Win32). This replaces mod_dld.c. Use SharedModule
        instead of AddModule in Configuration to build shared modules
        [Sameer Parekh, Paul Sutton]
  -  
  +
     *) Minor cleanups to r->finfo handling in some modules.
        [Dean Gaudet]
  -  
  +
     *) Abstract read()/write() to ap_read()/ap_write().
        Makes it easier to add other types of IO code such as SFIO.
        [Randy Terbush]
   
  -  *) Generalize default_port manipulations to make support of
  +  *) API: Generalize default_port manipulations to make support of
        different protocols easier. [Ben Laurie, Randy Terbush]
   
     *) There are many cases where users do not want Apache to form
        self-referential urls using the "canonical" ServerName and Port.
        The new UseCanonicalName directive (default on), if set to off
        will cause Apache to use the client-supplied hostname and port.
  -     Part of this change required a change to the construct_url()
  +     API: Part of this change required a change to the construct_url()
        prototype; and the addition of get_server_name() and
        get_server_port().
        [Michael Douglass <[EMAIL PROTECTED]>, Dean Gaudet]
  @@ -431,7 +434,7 @@
        an internal redirect occured.  Such redirects occur, for example,
        when processing a DirectoryIndex match.  [Dean Gaudet]
   
  -  *) table_add, table_merge, and table_set include implicit pstrdup()
  +  *) API: table_add, table_merge, and table_set include implicit pstrdup()
        of the key and value.  But in many cases this is not required
        because the key/value is a constant, or the value has been built
        by pstrcat() or other similar means.  New routines table_addn,
  @@ -464,8 +467,8 @@
        [Martin Kraemer, with code from [EMAIL PROTECTED] (Peter Wemm)
        taken from tcsh]
   
  -  *) "typedef array_header table" removed from alloc.h, folks should have
  -     been writing to use table as if it were an opaque type, but even
  +  *) API: "typedef array_header table" removed from alloc.h, folks should
  +     have been writing to use table as if it were an opaque type, but even
        some standard modules got this wrong.  By changing the definition
        to "typedef struct table table" module authors will receive compile
        time warnings that they're doing the wrong thing.  This change
  @@ -473,7 +476,7 @@
        structures.  Specifically, module authors should be using table_elts()
        to get access to an array_header * for the table. [Dean Gaudet]
   
  -  *) Renamed new_connection() to avoid namespace collision with LDAP
  +  *) API: Renamed new_connection() to avoid namespace collision with LDAP
        library routines.  [Ken Coar, Rasmus Lerdorf]
   
     *) WIN32: mod_speling is now available on the Win32 platform.
  @@ -513,7 +516,7 @@
   
     *) Fix Y2K problem with date printing in suexec log.
        [Paul Eggert <[EMAIL PROTECTED]>] PR#1343
  -  
  +
     *) WIN32 deserves a pid file.  [Ben Hyde]
   
     *) suexec errors now include the errno/description.  [Marc Slemko] PR#1543
  @@ -568,7 +571,7 @@
     *) SECURITY: Eliminate possible buffer overflow in cfg_getline, which
        is used to read various types of files such as htaccess and
        htpasswd files.  [Marc Slemko]
  -  
  +
     *) SECURITY: Ensure that the buffer returned by ht_time is always
        properly null terminated.  [Marc Slemko]
   
  @@ -591,7 +594,7 @@
        set with SetEnv/BrowserMatch and similar directives.
        [Dean Gaudet]
   
  -  *) Mod_speling returned incorrect HREF's when an ambigous match
  +  *) mod_speling returned incorrect HREF's when an ambigous match
        was found. Noticed by <[EMAIL PROTECTED]> (Soeren Ziehe)
        [EMAIL PROTECTED] (Soeren Ziehe), Martin Kraemer]
   
  @@ -651,7 +654,7 @@
     *) no2slash() was O(n^2) in the length of the input.  Make it O(n).
        [Dean Gaudet]
   
  -  *) migration from strncpy() to our "enhanced" version called
  +  *) API: migration from strncpy() to our "enhanced" version called
        ap_cpystrn() for performance and functionality reasons.
        Located in libap.a.  [Jim Jagielski]
   
  @@ -659,8 +662,10 @@
        multiple occurrences of the same key. [Stephen Scheck
         <[EMAIL PROTECTED]>, Ben Laurie] PR#1604
   
  -  *) Correct handling of quotation marks in AuthName realm names; as a
  -     byproduct, a new function: ap_escape_quotes().  [Ken Coar] PR#1195
  +  *) The AuthName must now be enclosed in quotes if it is to contain
  +     spaces.  [Ken Coar] PR#1195
  +
  +  *) API: new function: ap_escape_quotes(). [Ken Coar] PR#1195
   
     *) WIN32: Work around optimiser bug that killed ISAPI in release
        versions. [Ben Laurie] PR#1533
  @@ -669,9 +674,9 @@
   
     *) Interim (slow) fix for p->sub_pool critical sections in
        alloc.c (affects win32 only).  [Ben Hyde]
  -  
  +
     *) non-WIN32 was missing destroy_mutex definition.  [Ben Hyde]
  -  
  +
     *) send_fd_length() did not calculate total_bytes_sent properly.
        [Ben Reser <[EMAIL PROTECTED]>] PR#1366
   
  @@ -688,7 +693,7 @@
        mod_autoindex, mod_php3 which all use bputc()/bputs() of smaller
        strings in some cases.  The result would be extra effort
        setting up writev(), and in many cases extra effort building
  -     chunks.  The default is 31, it can be override at compile
  +     chunks.  The default is 31, it can be overriden at compile
        time. [Dean Gaudet]
   
     *) Move the gid switching code into the child so that log files
  @@ -709,13 +714,13 @@
     *) ap_snprintf() with a len of 0 behaved like sprintf().  This is not
        useful, and isn't what the standards require.  Now it returns 0
        and writes nothing.  [Dean Gaudet]
  -  
  +
     *) When an error occurs in fcntl() locking suggest the user look up
        the docs for LockFile.  [Dean Gaudet]
   
     *) Eliminate some dead code from writev_it_all().
        [Igor Tatarinov <[EMAIL PROTECTED]>]
  -  
  +
     *) mod_autoindex had an fread() without checking the result code.
        It also wouldn't handle "AddIconByType (TXT,/icons/text.gif text/*"
        (note the missing closing paren) properly.  [Dean Gaudet]
  @@ -892,7 +897,7 @@
   
     *) A sed command in the Configure script pushed the edge of POSIXness,
        breaking on some systems.  [Bhaba R.Misra <[EMAIL PROTECTED]>] PR#1368
  -  
  +
     *) Solaris >= 2.5 was totally broken due to a mess up using pthread
        mutexes.  [Roy Fielding, Dean Gaudet]
   
  @@ -1332,7 +1337,7 @@
        - Regex <Directory>s are applied after all non-regex <Directory>s.
   
       [Dean Gaudet]
  -  
  +
     *) Fix a bug introduced in 1.3a1 directory_walk regarding .htaccess files
        and corrupted paths.  [Dean Gaudet]
   
  @@ -1449,7 +1454,7 @@
        once per "heavy-weight process" just before a server child exit()'s 
        e.g. when max_requests_per_child is reached, etc.
        [Doug MacEachern, Dean Gaudet]
  -  
  +
     *) mod_include cleanup showed that handle_else was being used to handle
        endif.  It didn't cause problems, but it was cleaned up too.
        [Howard Fear]
  @@ -1538,7 +1543,7 @@
   
     *) added transport handle slot (t_handle) to the BUFF structure
        [Doug MacEachern]
  -     
  +
     *) get_client_block() returns wrong length if policy is
        REQUEST_CHUNKED_DECHUNK.
        [Kenichi Hori <[EMAIL PROTECTED]>] PR#815
  @@ -1546,7 +1551,7 @@
     *) Support the image map format of FrontPage.  For example:
           rect /url.hrm 10 20 30 40
        ["Chris O'Byrne" <[EMAIL PROTECTED]>] PR#807
  -  
  +
     *) PORT: -lresolv and -lsocks were in the wrong order for Solaris.
        ["Darren O'Shaughnessy" <[EMAIL PROTECTED]>] PR#846
   
  @@ -1561,7 +1566,7 @@
     *) Support Proxy Authentication, and don't pass the Proxy-Authorize
        header to the remote host in the proxy. [Sameer Parekh and
        Wallace]
  -  
  +
     *) Upgraded mod_rewrite from 3.0.6+ to latest officially available version
        3.0.9. This upgrade includes: fixed deadlooping on rewriting to same
        URLs, fixed rewritelog(), fixed forced response code handling on
  @@ -1576,11 +1581,11 @@
        the author now has gifted mod_rewrite exclusively to the Apache Group 
and 
        no longer maintains an external version.
        [Ralf S. Engelschall]
  -  
  +
     *) API: Added child_init function to module structure.  This is called
        once per "heavy-weight process" before any requests are handled.
        See http_config.h for more details.  [Dean Gaudet]
  -  
  +
     *) Anonymous_LogEmail was logging on each subrequest.
        [Dean Gaudet] PR#421, 868
   
  @@ -1647,7 +1652,7 @@
     *) CONFIG: "HostnameLookups" now defaults to off because it is far better
        for the net if we require people that actually need this data to
        enable it.  [Linus Torvalds]
  -  
  +
     *) directory_walk() is an expensive function, keep a little more state to
        avoid needless string counting.  Add two new functions 
make_dirstr_parent
        and make_dirstr_prefix which replace all existing uses of make_dirstr.
  @@ -1661,7 +1666,7 @@
   
     *) run_method optimized to avoid needless scanning over NULLs in the
        module list.  [Dean Gaudet]
  -  
  +
     *) Revamp of (unix) scoreboard management code such that it avoids
        unnecessary traversals of the scoreboard on each hit.  This is
        particularly important for high volume sites with a large
  @@ -1681,7 +1686,7 @@
        compile time.  The default sfio discipline will behave as apache
        would without sfio compiled in.
        [Doug MacEachern]
  -                
  +
     *) Enhance UserDir directive (mod_userdir) to accept a list of
        usernames for the 'disable' keyword, and add 'enable user...' to
        selectively *en*able userdirs if they're globally disabled.
  @@ -1701,7 +1706,7 @@
   
     *) Turn off chunked encoding after sending terminating chunk/footer
        so that we can't do it twice by accident. [Roy Fielding]
  -  
  +
     *) mod_expire also issues Cache-Control: max-age headers.
        [Rob Hartill]
   
  @@ -1755,7 +1760,7 @@
     *) table_set() and table_unset() did not deal correctly with
        multiple occurrences of the same key. [Stephen Scheck
        <[EMAIL PROTECTED]>, Ben Laurie] PR#1604
  -  
  +
     *) send_fd_length() did not calculate total_bytes_sent properly in error
        cases.  [Ben Reser <[EMAIL PROTECTED]>] PR#1366
   
  @@ -2074,7 +2079,7 @@
   
     *) PORT: Workaround for AIX 3.x compiler bug in http_bprintf.c.  
        [Marc Slemko] PR#725
  -  
  +
     *) PORT: fix problem compiling http_bprintf.c with gcc under SCO
        [Marc Slemko] PR#695
   
  
  
  

Reply via email to