Re: g_strjoinv() is very slow



On Sun, 24 Sep 2000, David Odin wrote:

> On Sun, Sep 24, 2000 at 12:39:01PM -0500, Raja R Harinath wrote:
> > 
> > The decision to use stpcpy is IMO independent of providing g_stpcpy().
> > It is quite a simple function, and is usually a better alternative to
> > strcat (at least Ulrich Drepper says so :-) -- so we should use it.
> >
>   I agree with Ulrich :-)

> > >        s = va_arg (args, gchar*);
> > >        strcat (string, s);
> > > +      ptr = string + strlen (s);
> > >  
> > >        s = va_arg (args, gchar*);
> > >        while (s)
> > >  	{
> > > -	  strcat (string, separator);
> > > -	  strcat (string, s);
> > > +          ptr = g_stpcpy(ptr, separator);
> > > +          ptr = g_stpcpy(ptr, s);
> > 
> > Similar comments. 
> > 
>     OK. Thanks for all your comments. 
>  I've attached a new version which takes all your remarks in account.

ok, one extra round, mostly for stylistic issues,
and i think we'll be done with it ;)

> 
>         Best regards,
> 
>                    DindinX
> 


> diff -Nrudb glib.orig/glib.h glib/glib.h
> --- glib.orig/glib.h	Tue Sep 19 16:30:35 2000
> +++ glib/glib.h	Sun Sep 24 19:55:55 2000
> @@ -1761,8 +1761,8 @@
>  gchar*   g_strjoinv		(const gchar  *separator,
>  				 gchar       **str_array);
>  void     g_strfreev		(gchar       **str_array);
> -
> -
> +gchar*   g_stpcpy     (gchar *dest,
> +                       const char *src);

please align the aguments.

>  /* calculate a string size, guarranteed to fit format + args.
>   */
> diff -Nrudb glib.orig/gstrfuncs.c glib/gstrfuncs.c
> --- glib.orig/gstrfuncs.c	Sun Sep 10 18:04:33 2000
> +++ glib/gstrfuncs.c	Sun Sep 24 20:05:07 2000
> @@ -118,6 +118,21 @@
>    return str;
>  }
>  
> +gchar *
> +g_stpcpy (gchar *dest,
> +          const gchar *src)

argument alignment

> +{
> +  g_return_val_if_fail (dest != NULL, NULL);
> +  g_return_val_if_fail (src != NULL, NULL);
> +
> +#ifdef HAVE_STPCPY
> +  return stpcpy (dest, src);
> +#else
> +  strcpy(dest, src);
> +  return dest+strlen(src);

stylistic: put spaces around '+' and before opening paranthesis.
as far as the implementation is concerned, something like the
glibc version is probably more efficient:

/* Copy SRC to DEST, returning the address of the terminating '\0' in DEST.  */
char *
__stpcpy (dest, src)
     char *dest;
     const char *src;
{
  register char *d = dest;
  register const char *s = src;

  do
    *d++ = *s;
  while (*s++ != '\0');

  return d - 1;
}

(if strcpy()+strlen() would really be more efficient,
ulrich probably had used it there)

[...]

the rest of the patch seems pretty ok to me, just align stuff,
add missing spaces, glib-ify the above strpcpy version, and
supply a ChangeLog entry.
                        
---
ciaoTJ





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]