httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gst...@apache.org
Subject cvs commit: httpd-2.0/modules/dav/main util.c
Date Fri, 27 Apr 2001 05:27:01 GMT
gstein      01/04/26 22:27:01

  Modified:    modules/dav/main util.c
  Log:
  fast-path some cases, primarily to avoid an allocation when it isn't needed.
  for a "nice" piece of cdata which is in one chunk, this can usually avoid an
  allocation.
  
  Revision  Changes    Path
  1.29      +26 -5     httpd-2.0/modules/dav/main/util.c
  
  Index: util.c
  ===================================================================
  RCS file: /home/cvs/httpd-2.0/modules/dav/main/util.c,v
  retrieving revision 1.28
  retrieving revision 1.29
  diff -u -u -r1.28 -r1.29
  --- util.c	2001/04/17 11:07:09	1.28
  +++ util.c	2001/04/27 05:27:00	1.29
  @@ -334,15 +334,36 @@
       char *cdata;
       char *s;
       apr_size_t tlen;
  +    const char *found_text;
  +    int found_count = 0;
   
  -    for (scan = elem->first_cdata.first; scan != NULL; scan = scan->next)
  -        len += strlen(scan->text);
  +    for (scan = elem->first_cdata.first; scan != NULL; scan = scan->next) {
  +        found_text = scan->text;
  +        ++found_count;
  +        len += strlen(found_text);
  +    }
   
       for (child = elem->first_child; child != NULL; child = child->next) {
           for (scan = child->following_cdata.first;
                scan != NULL;
  -             scan = scan->next)
  -            len += strlen(scan->text);
  +             scan = scan->next) {
  +            found_text = scan->text;
  +            ++found_count;
  +            len += strlen(found_text);
  +        }
  +    }
  +
  +    /* some fast-path cases:
  +     * 1) zero-length cdata
  +     * 2) a single piece of cdata with no whitespace to strip
  +     */
  +    if (len == 0)
  +        return "";
  +    if (found_count == 1) {
  +        if (!strip_white
  +            || (!apr_isspace(*found_text)
  +                && !apr_isspace(found_text[len - 1])))
  +            return found_text;
       }
   
       cdata = s = apr_palloc(pool, len + 1);
  @@ -365,7 +386,7 @@
   
       *s = '\0';
   
  -    if (strip_white && len > 0) {
  +    if (strip_white) {
           /* trim leading whitespace */
           while (apr_isspace(*cdata))     /* assume: return false for '\0' */
               ++cdata;
  
  
  

Mime
View raw message