You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@apr.apache.org by dean gaudet <de...@arctic.org> on 2001/07/18 01:59:56 UTC
Re: apr_strcat optimization(s)
you might as well memcpy() if you're going to strlen() first. it's less
complex inline code.
-dean
On Tue, 19 Jun 2001, Doug MacEachern wrote:
> the current apr_strcat does strlen() twice for each argument, this patch
> makes it happen just once. it would also be handy to have an apr_pstrcatn
> (name debatable) that returns the calculated length so the caller can
> avoid another strlen(), something like:
>
> apr_size_t total_len;
> apr_status_t status = apr_pstrcatn(pool, &total_len, ..., NULL);
>
> then apr_pstrcat() would just be a wrapper around apr_pstrcatn().
> i'll get a patch together if the name/prototype is agreed on.
>
> --- srclib/apr/strings/apr_strings.c 2001/05/10 18:05:18 1.13
> +++ srclib/apr/strings/apr_strings.c 2001/06/19 17:12:01
> @@ -137,8 +137,9 @@
> va_start(adummy, a);
>
> while ((argp = va_arg(adummy, char *)) != NULL) {
> - strcpy(cp, argp);
> - cp += strlen(argp);
> + len = strlen(argp);
> + strncpy(cp, argp, len);
> + cp += len;
> }
>
> va_end(adummy);
>
>
>
Re: apr_strcat optimization(s)
Posted by dean gaudet <de...@arctic.org>.
btw, if you study the assembly for any inline strcpy() implementation
you'll find it has a pointer to the end (NUL) of the result anyhow. in
some ancient msdos/windows/os2/etc. c libraries there is a function
stpcpy() which returns the pointer to the end of the result, which is
probably a million times more useful than returning the result again.
(you can see i stuck my_stpcpy() into mod_test_util_uri.c ... of course
it's not a nicely optimised inline version :)
-dean
On Tue, 17 Jul 2001, dean gaudet wrote:
> you might as well memcpy() if you're going to strlen() first. it's less
> complex inline code.
>
> -dean
>
> On Tue, 19 Jun 2001, Doug MacEachern wrote:
>
> > the current apr_strcat does strlen() twice for each argument, this patch
> > makes it happen just once. it would also be handy to have an apr_pstrcatn
> > (name debatable) that returns the calculated length so the caller can
> > avoid another strlen(), something like:
> >
> > apr_size_t total_len;
> > apr_status_t status = apr_pstrcatn(pool, &total_len, ..., NULL);
> >
> > then apr_pstrcat() would just be a wrapper around apr_pstrcatn().
> > i'll get a patch together if the name/prototype is agreed on.
> >
> > --- srclib/apr/strings/apr_strings.c 2001/05/10 18:05:18 1.13
> > +++ srclib/apr/strings/apr_strings.c 2001/06/19 17:12:01
> > @@ -137,8 +137,9 @@
> > va_start(adummy, a);
> >
> > while ((argp = va_arg(adummy, char *)) != NULL) {
> > - strcpy(cp, argp);
> > - cp += strlen(argp);
> > + len = strlen(argp);
> > + strncpy(cp, argp, len);
> > + cp += len;
> > }
> >
> > va_end(adummy);
> >
> >
> >
>
>