Re: [Evolution-hackers] [evolution-patches] Avoiding a strdup in camel-folder-summar.c
On Wed, 2006-07-12 at 02:28 +0530, Ritesh Khadgaray wrote: 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; That will free the token in the list. Chris ___ Evolution-hackers mailing list Evolution-hackers@gnome.org http://mail.gnome.org/mailman/listinfo/evolution-hackers
Re: [Evolution-hackers] [evolution-patches] Avoiding a strdup in camel-folder-summar.c
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; -- Ritesh Khadgaray LinuX N Stuff Ph: +919822394463 Eat Right, Exercise, Die Anyway. ___ Evolution-hackers mailing list Evolution-hackers@gnome.org http://mail.gnome.org/mailman/listinfo/evolution-hackers
Re: [Evolution-hackers] [evolution-patches] Avoiding a strdup in camel-folder-summar.c
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 ___ Evolution-hackers mailing list Evolution-hackers@gnome.org http://mail.gnome.org/mailman/listinfo/evolution-hackers
Re: [Evolution-hackers] [evolution-patches] Avoiding a strdup in camel-folder-summar.c
On Tue, 2006-07-11 at 17:06 -0400, Chris Toshok wrote: On Wed, 2006-07-12 at 02:28 +0530, Ritesh Khadgaray wrote: 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; That will free the token in the list. Oops. Einstein moment. Thanks :) -- Ritesh Khadgaray LinuX N Stuff Ph: +919822394463 Eat Right, Exercise, Die Anyway. ___ Evolution-hackers mailing list Evolution-hackers@gnome.org http://mail.gnome.org/mailman/listinfo/evolution-hackers
Re: [Evolution-hackers] [evolution-patches] Avoiding a strdup in camel-folder-summar.c
On Tue, 2006-07-11 at 09:28 -0400, Chris Toshok wrote: static void free_token (gchar *token) { gint i; for (i = 0; i tokens_len; i ++) if (tokens[i] == token) return; g_free (token); } ps. Maybe for real efficiency you can also check whether the address of token pointer isn't between the first and the last element of the static table ;-)? No really, yours is better. The point of my patch was to show that the strdup can be avoided (and that valgrind shows me a significant reduc- tion in used memory .. if you indeed avoid it). -- Philip Van Hoof, software developer at x-tend home: me at pvanhoof dot be gnome: pvanhoof at gnome dot org work: vanhoof at x-tend dot be http://www.pvanhoof.be - http://www.x-tend.be ___ Evolution-hackers mailing list Evolution-hackers@gnome.org http://mail.gnome.org/mailman/listinfo/evolution-hackers
Re: [Evolution-hackers] [evolution-patches] Avoiding a strdup in camel-folder-summar.c
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; g_free (token); } ___ Evolution-hackers mailing list Evolution-hackers@gnome.org http://mail.gnome.org/mailman/listinfo/evolution-hackers
Re: [Evolution-hackers] [evolution-patches] Avoiding a strdup in camel-folder-summar.c
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; for (i = 0; i tokens_len; i ++) if (tokens[i] == token) return; g_free (token); } Of course. Yes, that is better. -- Philip Van Hoof, software developer at x-tend home: me at pvanhoof dot be gnome: pvanhoof at gnome dot org work: vanhoof at x-tend dot be http://www.pvanhoof.be - http://www.x-tend.be ___ Evolution-hackers mailing list Evolution-hackers@gnome.org http://mail.gnome.org/mailman/listinfo/evolution-hackers