httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bri...@apache.org
Subject cvs commit: httpd-2.0/modules/http mod_mime.c
Date Fri, 07 Dec 2001 08:19:44 GMT
brianp      01/12/07 00:19:44

  Modified:    modules/http mod_mime.c
  Log:
  Optimized away some string scans and copies in analyze_ct()
  
  Revision  Changes    Path
  1.72      +28 -27    httpd-2.0/modules/http/mod_mime.c
  
  Index: mod_mime.c
  ===================================================================
  RCS file: /home/cvs/httpd-2.0/modules/http/mod_mime.c,v
  retrieving revision 1.71
  retrieving revision 1.72
  diff -u -r1.71 -r1.72
  --- mod_mime.c	2001/12/07 03:44:29	1.71
  +++ mod_mime.c	2001/12/07 08:19:44	1.72
  @@ -465,10 +465,8 @@
       return OK;
   }
   
  -static char *zap_sp(char *s)
  +static const char *zap_sp(const char *s)
   {
  -    char *tp;
  -
       if (s == NULL) {
   	return (NULL);
       }
  @@ -476,17 +474,27 @@
   	return (s);
       }
   
  -    /* delete prefixed white space */
  +    /* skip prefixed white space */
       for (; *s == ' ' || *s == '\t' || *s == '\n'; s++);
   
  -    /* delete postfixed white space */
  -    for (tp = s; *tp != '\0'; tp++);
  -    for (tp--; tp != s && (*tp == ' ' || *tp == '\t' || *tp == '\n'); tp--) {
  -	*tp = '\0';
  -    }
       return (s);
   }
   
  +static char *zap_sp_and_dup(apr_pool_t *p, const char *start,
  +                            const char *end, apr_size_t *len)
  +{
  +    while ((start < end) && apr_isspace(*start)) {
  +        start++;
  +    }
  +    while ((end > start) && apr_isspace(*(end - 1))) {
  +        end--;
  +    }
  +    if (len) {
  +        *len = end - start;
  +    }
  +    return apr_pstrmemdup(p, start, end - start);
  +}
  +
   static int is_token(char c)
   {
       int res;
  @@ -505,7 +513,7 @@
       return res;
   }
   
  -static int is_quoted_pair(char *s)
  +static int is_quoted_pair(const char *s)
   {
       int res = -1;
       int c;
  @@ -519,9 +527,10 @@
       return (res);
   }
   
  -static content_type *analyze_ct(request_rec *r, char *s)
  +static content_type *analyze_ct(request_rec *r, const char *s)
   {
  -    char *tp, *mp, *cp;
  +    const char *cp;
  +    const char *mp;
       char *attribute, *value;
       int quoted = 0;
       server_rec * ss = r->server;
  @@ -535,11 +544,8 @@
       ctp->type = NULL;
       ctp->subtype = NULL;
       ctp->param = NULL;
  -
  -    tp = apr_pstrdup(p, s);
   
  -    mp = tp;
  -    cp = mp;
  +    mp = s;
   
       /* getting a type */
       if (!(cp = strchr(mp, '/'))) {
  @@ -548,8 +554,7 @@
   		     (const char *) mp);
   	return (NULL);
       }
  -    ctp->type = apr_pstrmemdup(p, mp, cp - mp);
  -    ctp->type = zap_sp(ctp->type);
  +    ctp->type = zap_sp_and_dup(p, mp, cp, NULL);
       if (ctp->type == NULL || *(ctp->type) == '\0' ||
   	strchr(ctp->type, ';') || strchr(ctp->type, ' ') ||
   	strchr(ctp->type, '\t')) {
  @@ -564,17 +569,15 @@
   
       for (; *cp != ';' && *cp != '\0'; cp++)
           continue;
  -    ctp->subtype = apr_pstrndup(p, mp, cp - mp);
  -    ctp->subtype = zap_sp(ctp->subtype);
  +    ctp->subtype = zap_sp_and_dup(p, mp, cp, NULL);
       if ((ctp->subtype == NULL) || (*(ctp->subtype) == '\0') ||
   	strchr(ctp->subtype, ' ') || strchr(ctp->subtype, '\t')) {
   	ap_log_error(APLOG_MARK, APLOG_WARNING, 0, ss,
   		     "Cannot get media subtype.");
   	return (NULL);
       }
  -    cp = zap_sp(cp);
  -    if (cp == NULL || *cp == '\0') {
  -	return (ctp);
  +    if (*cp == '\0') {
  +        return (ctp);
       }
   
       /* getting parameters */
  @@ -600,8 +603,7 @@
   		continue;
   	    }
   	    else if (*cp == '=') {
  -		attribute = apr_pstrndup(p, mp, cp - mp);
  -		attribute = zap_sp(attribute);
  +		attribute = zap_sp_and_dup(p, mp, cp, NULL);
   		if (attribute == NULL || *attribute == '\0') {
   		    ap_log_error(APLOG_MARK, APLOG_WARNING, 0, ss,
   				 "Cannot get media parameter.");
  @@ -675,8 +677,7 @@
   		    }
   		}
   	    }
  -	    value = apr_pstrndup(p, mp, cp - mp);
  -	    value = zap_sp(value);
  +	    value = zap_sp_and_dup(p, mp, cp, NULL);
   	    if (value == NULL || *value == '\0') {
   		ap_log_error(APLOG_MARK, APLOG_WARNING, 0, ss,
   			     "Cannot get media parameter.");
  
  
  

Mime
View raw message