Memory improvement for the tokens in camel_folder_summary.c

Philip Van Hoof <[email protected]>
Newsgroups gmane.comp.gnome.evolution.patches
Message-ID <[email protected]>
This patch is unrelated to the mmap summaries.

It improves memory handling of the tokens in camel_folder_summary.c.

Who can check the patch for me and give approval to commit if okay?

Thanks

-- 
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-patches mailing list
[email protected]
http://mail.gnome.org/mailman/listinfo/evolution-patches
camel__tokens.diff (text/x-patch, 3.2 KB)
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/evolution-data-server/ChangeLog,v
retrieving revision 1.407
diff -u -p -r1.407 ChangeLog
--- ChangeLog	10 Jul 2006 14:23:55 -0000	1.407
+++ ChangeLog	20 Jul 2006 20:21:25 -0000
@@ -1,3 +1,8 @@
+2006-07-20  Philip Van Hoof  <[email protected]>
+
+	* camel/camel-folder-summary.c: Better handling of
+	memory for tokens
+
 2006-07-10  Harish Krishnaswamy  <[email protected]>
 
 	* configure.in, NEWS: EDS 1.7.4 release updates
Index: camel/camel-folder-summary.c
===================================================================
RCS file: /cvs/gnome/evolution-data-server/camel/camel-folder-summary.c,v
retrieving revision 1.149
diff -u -p -r1.149 camel-folder-summary.c
--- camel/camel-folder-summary.c	6 Jul 2006 19:43:46 -0000	1.149
+++ camel/camel-folder-summary.c	20 Jul 2006 20:21:32 -0000
@@ -1242,6 +1242,42 @@ static char * tokens[] = {
 
 #define tokens_len (sizeof(tokens)/sizeof(tokens[0]))
 
+
+guint bytes;
+static gchar* 
+token_add (gchar *str)
+{
+	int i;
+
+	if (!str)
+		return NULL;
+
+	for (i=0; i<tokens_len; i++)
+		if (!strcmp (str, tokens[i]))
+		{
+			g_free (str);
+			return tokens[i];
+		}
+
+	return (gchar*) camel_pstring_add (str, FALSE);
+}
+
+
+static void
+token_free (gchar *token)
+{
+        gint i;
+
+	if (!token)
+		return;
+
+        for (i = 0; i < tokens_len; i ++)
+                if (tokens[i] == token)
+                        return;
+
+        camel_pstring_free (token);
+}
+
 /* baiscally ...
     0 = null
     1-tokens_len == tokens[id-1]
@@ -1339,7 +1375,7 @@ camel_folder_summary_decode_token(FILE *
 		if (len <= 0) {
 			ret = NULL;
 		} else if (len<= tokens_len) {
-			ret = g_strdup(tokens[len-1]);
+			ret = tokens[len-1];
 		} else {
 			io(printf ("Invalid token encountered: %d", len));
 			*str = NULL;
@@ -1845,10 +1881,10 @@ content_info_new_from_header(CamelFolder
 	ci = camel_folder_summary_content_info_new (s);
 	
 	charset = e_iconv_locale_charset ();
-	ci->id = camel_header_msgid_decode (camel_header_raw_find (&h, "content-id", NULL));
-	ci->description = camel_header_decode_string (camel_header_raw_find (&h, "content-description", NULL), charset);
-	ci->encoding = camel_content_transfer_encoding_decode (camel_header_raw_find (&h, "content-transfer-encoding", NULL));
-	ci->type = camel_content_type_decode(camel_header_raw_find(&h, "content-type", NULL));
+	ci->id = token_add (camel_header_msgid_decode (camel_header_raw_find (&h, "content-id", NULL)));
+	ci->description = token_add (camel_header_decode_string (camel_header_raw_find (&h, "content-description", NULL), charset));
+	ci->encoding = token_add (camel_content_transfer_encoding_decode (camel_header_raw_find (&h, "content-transfer-encoding", NULL)));
+	ci->type = token_add (camel_content_type_decode(camel_header_raw_find(&h, "content-type", NULL)));
 
 	return ci;
 }
@@ -1937,9 +1973,9 @@ static void
 content_info_free(CamelFolderSummary *s, CamelMessageContentInfo *ci)
 {
 	camel_content_type_unref(ci->type);
-	g_free(ci->id);
-	g_free(ci->description);
-	g_free(ci->encoding);
+	token_free (ci->id);
+	token_free (ci->description);
+	token_free (ci->encoding);
 	e_memchunk_free(s->content_info_chunks, ci);
 }
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.