You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by br...@apache.org on 2001/12/02 06:09:51 UTC

cvs commit: httpd-2.0/server util.c

brianp      01/12/01 21:09:51

  Modified:    server   util.c
  Log:
  Modified ap_make_full_path to minimize the number of strlen operations
  
  Revision  Changes    Path
  1.115     +19 -9     httpd-2.0/server/util.c
  
  Index: util.c
  ===================================================================
  RCS file: /home/cvs/httpd-2.0/server/util.c,v
  retrieving revision 1.114
  retrieving revision 1.115
  diff -u -r1.114 -r1.115
  --- util.c	2001/09/14 23:26:27	1.114
  +++ util.c	2001/12/02 05:09:51	1.115
  @@ -1692,16 +1692,26 @@
   AP_DECLARE(char *) ap_make_full_path(apr_pool_t *a, const char *src1,
   				  const char *src2)
   {
  -    register int x;
  +    apr_size_t len1, len2;
  +    char *path;
   
  -    x = strlen(src1);
  -    if (x == 0)
  -	return apr_pstrcat(a, "/", src2, NULL);
  -
  -    if (src1[x - 1] != '/')
  -	return apr_pstrcat(a, src1, "/", src2, NULL);
  -    else
  -	return apr_pstrcat(a, src1, src2, NULL);
  +    len1 = strlen(src1);
  +    len2 = strlen(src2);
  +    path = (char *)apr_palloc(a, len1 + len2 + 2); /* +2 for '/' plus null */
  +    if (len1 == 0) {
  +        *path = '/';
  +        memcpy(path + 1, src2, len2 + 1);
  +    }
  +    else {
  +        char *next;
  +        memcpy(path, src1, len1);
  +        next = path + len1;
  +        if (next[-1] != '/') {
  +            *next++ = '/';
  +        }
  +        memcpy(next, src2, len2 + 1);
  +    }
  +    return path;
   }
   
   /*