Re: [evolution-patches] Avoiding a strdup in camel-folder-summar.c

Jeffrey Stedfast <[email protected]>
Newsgroups gmane.comp.gnome.evolution.patches,gmane.comp.gnome.evolution.devel
Message-ID <1152716510.20636.11.camel__8028.65277878499$1152717249$gmane$org@linux.site>
On Wed, 2006-07-12 at 02:27 +0530, Ritesh Khadgaray wrote:
> On Tue, 2006-07-11 at 09:28 -0400, Chris Toshok wrote:
> > No opinion on the rest of the patch, but this:
> > 
> > > +static void
> > > +free_token (gchar *token)
> > > +{
> > > +       gint i=0;
> > > +       gboolean no=FALSE;
> > > +
> > > +       for (i=0; (i < tokens_len); i++)
> > > +       {
> > > +               if (tokens[i] == token)
> > > +                       no = TRUE;
> > > +       }
> > > +
> > > +       if (!no)
> > > +               g_free (token);
> > > +}
> > > + 
> > 
> > is more efficient as:
> > 
> > static void
> > free_token (gchar *token)
> > {
> > 	gint i;
> > 
> > 	for (i = 0; i < tokens_len; i ++)
> > 		if (tokens[i] == token)
> > 			return;
> 
> out of curiosity, the first patch reads through the list
> and this patch, return if any one of the token is equal, anf not any
> following it.
> 
> Would the below not be better ?
> 
> 	for (i = 0; i < tokens_len; i ++)
> 		if (tokens[i] == token)
> 			break;
> 
> 

no, because you'd segfault trying to g_free() a static string.

The point of the code Toshok wrote was to no-op if the string was static
and to g_free() it if not.

Jeff

-- 
Jeffrey Stedfast
Evolution Hacker - Novell, Inc.
[email protected]  - www.novell.com
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.