dgaudet     98/03/13 16:32:08

  Modified:    src/include alloc.h
               src/main alloc.c util_uri.c
  Log:
  I really don't think any other definition of pstrndup() makes sense --
  especially since it always allocates n+1 bytes of memory, even if I go
  back to its original definition.  And on examination, all of our uses
  of pstrndup() are cases where we want a substring of another string, and
  we know the substring is of a certain length.  So speed up pstrndup() by
  using memcpy().  (This small change was worth another 50% performance
  boost when I tested it on test-util-uri.)
  
  Revision  Changes    Path
  1.48      +1 -0      apache-1.3/src/include/alloc.h
  
  Index: alloc.h
  ===================================================================
  RCS file: /export/home/cvs/apache-1.3/src/include/alloc.h,v
  retrieving revision 1.47
  retrieving revision 1.48
  diff -u -r1.47 -r1.48
  --- alloc.h   1998/03/09 22:42:54     1.47
  +++ alloc.h   1998/03/14 00:32:05     1.48
  @@ -115,6 +115,7 @@
   API_EXPORT(void *) palloc(struct pool *, int nbytes);
   API_EXPORT(void *) pcalloc(struct pool *, int nbytes);
   API_EXPORT(char *) pstrdup(struct pool *, const char *s);
  +/* make a nul terminated copy of the n characters starting with s */
   API_EXPORT(char *) pstrndup(struct pool *, const char *s, int n);
   API_EXPORT(char *) pstrcat(struct pool *,...);       /* all '...' must be 
char* */
   
  
  
  
  1.77      +3 -1      apache-1.3/src/main/alloc.c
  
  Index: alloc.c
  ===================================================================
  RCS file: /export/home/cvs/apache-1.3/src/main/alloc.c,v
  retrieving revision 1.76
  retrieving revision 1.77
  diff -u -r1.76 -r1.77
  --- alloc.c   1998/03/13 13:28:15     1.76
  +++ alloc.c   1998/03/14 00:32:06     1.77
  @@ -726,10 +726,12 @@
   API_EXPORT(char *) pstrndup(struct pool *a, const char *s, int n)
   {
       char *res;
  +
       if (s == NULL)
        return NULL;
       res = palloc(a, n + 1);
  -    ap_cpystrn(res, s, n + 1);
  +    memcpy(res, s, n);
  +    res[n] = '\0';
       return res;
   }
   
  
  
  
  1.11      +10 -25    apache-1.3/src/main/util_uri.c
  
  Index: util_uri.c
  ===================================================================
  RCS file: /export/home/cvs/apache-1.3/src/main/util_uri.c,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- util_uri.c        1998/03/13 08:13:54     1.10
  +++ util_uri.c        1998/03/14 00:32:07     1.11
  @@ -417,21 +417,6 @@
       uri_delims['\0'] = T_NUL;
   }
   
  -/* Since we know that the string we're duping is of exactly length l
  - * we don't need to go through the expensive (silly) pstrndup().  We
  - * can do much better on our own.  This is worth another 50%
  - * improvement.
  - */
  -static char *special_strdup(pool *p, const char *s, size_t l)
  -{
  -    char *d;
  -
  -    d = palloc(p, l + 1);
  -    memcpy(d, s, l);
  -    d[l] = '\0';
  -    return d;
  -}
  -
   /* parse_uri_components():
    * Parse a given URI, fill in all supplied fields of a uri_components
    * structure. This eliminates the necessity of extracting host, port,
  @@ -468,7 +453,7 @@
            ++s;
        }
        if (s != uri) {
  -         uptr->path = special_strdup(p, uri, s - uri);
  +         uptr->path = pstrndup(p, uri, s - uri);
        }
        if (*s == 0) {
            return HTTP_OK;
  @@ -478,7 +463,7 @@
            s1 = strchr(s, '#');
            if (s1) {
                uptr->fragment = pstrdup(p, s1 + 1);
  -             uptr->query = special_strdup(p, s, s1 - s);
  +             uptr->query = pstrndup(p, s, s1 - s);
            }
            else {
                uptr->query = pstrdup(p, s);
  @@ -500,14 +485,14 @@
        goto deal_with_path;    /* backwards predicted taken! */
       }
   
  -    uptr->scheme = special_strdup(p, uri, s - uri);
  +    uptr->scheme = pstrndup(p, uri, s - uri);
       s += 3;
       hostinfo = s;
       while ((uri_delims[*(unsigned char *)s] & NOTEND_HOSTINFO) == 0) {
        ++s;
       }
       uri = s; /* whatever follows hostinfo is start of uri */
  -    uptr->hostinfo = special_strdup(p, hostinfo, uri - hostinfo);
  +    uptr->hostinfo = pstrndup(p, hostinfo, uri - hostinfo);
   
       /* If there's a username:[EMAIL PROTECTED]:port, the @ we want is the 
last @...
        * too bad there's no memrchr()... For the C purists, note that hostinfo
  @@ -527,12 +512,12 @@
        s = memchr(hostinfo, ':', uri - hostinfo);
        if (s == NULL) {
            /* we expect the common case to have no port */
  -         uptr->hostname = special_strdup(p, hostinfo, uri - hostinfo);
  +         uptr->hostname = pstrndup(p, hostinfo, uri - hostinfo);
            goto deal_with_path;
        }
  -     uptr->hostname = special_strdup(p, hostinfo, s - hostinfo);
  +     uptr->hostname = pstrndup(p, hostinfo, s - hostinfo);
        ++s;
  -     uptr->port_str = special_strdup(p, s, uri - s);
  +     uptr->port_str = pstrndup(p, s, uri - s);
        if (uri != s) {
            port = strtol(uptr->port_str, &endstr, 10);
            uptr->port = port;
  @@ -549,12 +534,12 @@
       /* first colon delimits username:password */
       s1 = memchr(hostinfo, ':', s - hostinfo);
       if (s1) {
  -     uptr->user = special_strdup(p, hostinfo, s1 - hostinfo);
  +     uptr->user = pstrndup(p, hostinfo, s1 - hostinfo);
        ++s1;
  -     uptr->password = special_strdup(p, s1, s - s1);
  +     uptr->password = pstrndup(p, s1, s - s1);
       }
       else {
  -     uptr->user = special_strdup(p, hostinfo, s - hostinfo);
  +     uptr->user = pstrndup(p, hostinfo, s - hostinfo);
       }
       hostinfo = s + 1;
       goto deal_with_host;
  
  
  

Reply via email to