[evolution-patches] CamelFolderInfo's with GSlice



Hi there,

This patch attempts to replace the many different ways of allocating a
CamelFolderInfo with the gslice allocator.

I haven't measured yet whether this change is significant in terms of
memory consumption. I can imagine it's going to be a little bit faster.
Most people don't have thousands of folders, so maybe it's not going to
make a huge difference in memory consumption.

However. My opinion is that people should be using "the same" way for
allocating a specific structure. I've seen at least three different
methods in the code (g_malloc0, g_new0 and a _new). Sounds like a
constructor function is needed here?

It's a diff against my own version, but in that version not much has
changed in the affected files. If you need assistance applying the patch
on a original Camel, ask. It's a unified diff, so I don't think you'll
have a lot troubles.

I'm adding this one to the gslice tracker:
http://bugzilla.gnome.org/show_bug.cgi?id=363156

Note that the CamelPOP3FolderInfo's instance allocating isn't changed,
as that structure seems to be totally different. Some other providers
seemed to reuse the CamelFolderInfo infrastructure, so I've let them too
use the gslice allocs.


-- 
Philip Van Hoof, software developer
home: me at pvanhoof dot be
gnome: pvanhoof at gnome dot org
work: vanhoof at x-tend dot be
blog: http://pvanhoof.be/blog
Index: camel/camel-store.c
===================================================================
--- camel/camel-store.c	(revision 1044)
+++ camel/camel-store.c	(working copy)
@@ -711,7 +711,7 @@
 		g_free (vinfo->uri);
 	} else {
 		/* There wasn't a Trash/Junk folder so create a new folder entry */
-		vinfo = g_new0 (CamelFolderInfo, 1);
+		vinfo = g_slice_new (CamelFolderInfo);
 		
 		g_assert(parent != NULL);
 		
@@ -871,7 +871,7 @@
 		g_free (fi->name);
 		g_free (fi->full_name);
 		g_free (fi->uri);
-		g_free (fi);
+		g_slice_free (CamelFolderInfo, fi);
 	}
 }
 
@@ -943,7 +943,7 @@
 				CamelURL *url;
 				char *sep;
 
-				pfi = g_new0 (CamelFolderInfo, 1);
+				pfi = g_slice_new (CamelFolderInfo);
 				if (short_names) {
 					pfi->name = strrchr (pname, separator);
 					if (pfi->name)
Index: camel/providers/pop3/camel-pop3-folder.c
===================================================================
--- camel/providers/pop3/camel-pop3-folder.c	(revision 1044)
+++ camel/providers/pop3/camel-pop3-folder.c	(working copy)
@@ -193,7 +193,7 @@
 		ret = camel_pop3_stream_line(stream, &line, &len);
 		if (ret>=0) {
 			if (sscanf((char *) line, "%u %u", &id, &size) == 2) {
-				fi = g_malloc0(sizeof(*fi));
+				fi = g_malloc0 (sizeof(*fi));
 				fi->size = size;
 				fi->id = id;
 				fi->index = ((CamelPOP3Folder *)folder)->uids->len;
Index: camel/providers/imap/camel-imap-store.c
===================================================================
--- camel/providers/imap/camel-imap-store.c	(revision 1044)
+++ camel/providers/imap/camel-imap-store.c	(working copy)
@@ -1037,8 +1037,8 @@
 	const char *name;
 	CamelFolderInfo *fi;
 
-	fi = g_malloc0(sizeof(*fi));
-
+	fi = g_slice_new (CamelFolderInfo);
+	
 	fi->full_name = g_strdup(folder_name);
 	fi->unread = -1;
 	fi->total = -1;
@@ -2405,7 +2405,7 @@
 
 	flags = (flags & ~CAMEL_FOLDER_SUBSCRIBED) | (si->info.flags & CAMEL_STORE_FOLDER_INFO_SUBSCRIBED);
 
-	fi = g_new0 (CamelFolderInfo, 1);
+	fi = g_slice_new (CamelFolderInfo);
 	fi->full_name = g_strdup(camel_store_info_path(imap_store->summary, si));
 	if (!g_ascii_strcasecmp(fi->full_name, "inbox")) {
 		flags |= CAMEL_FOLDER_SYSTEM|CAMEL_FOLDER_TYPE_INBOX;
Index: camel/providers/local/camel-local-store.c
===================================================================
--- camel/providers/local/camel-local-store.c	(revision 1044)
+++ camel/providers/local/camel-local-store.c	(working copy)
@@ -486,7 +486,7 @@
 	g_free (str);
 	g_free (name);
 	
-	fi = g_new0 (CamelFolderInfo, 1);
+	fi = g_slice_new (CamelFolderInfo);
 	fi->full_name = g_strdup (folder_name);
 	fi->name = g_path_get_basename (folder_name);
 	fi->uri = g_strdup_printf ("%s:%s#%s", ((CamelService *) store)->url->protocol,
Index: camel/providers/local/camel-spool-store.c
===================================================================
--- camel/providers/local/camel-spool-store.c	(revision 1044)
+++ camel/providers/local/camel-spool-store.c	(working copy)
@@ -276,7 +276,7 @@
 	else
 		name = full;
 
-	fi = g_malloc0(sizeof(*fi));
+	fi = g_slice_new (CamelFolderInfo);
 	url = camel_url_copy(((CamelService *)store)->url);
 	camel_url_set_fragment(url, full);
 	fi->uri = camel_url_to_string(url, 0);
Index: camel/providers/local/camel-mh-store.c
===================================================================
--- camel/providers/local/camel-mh-store.c	(revision 1044)
+++ camel/providers/local/camel-mh-store.c	(working copy)
@@ -358,7 +358,7 @@
 	camel_url_set_fragment (url, path);
 	
 	/* Build the folder info structure. */
-	fi = g_malloc0(sizeof(*fi));
+	fi = g_slice_new (CamelFolderInfo);
 	fi->uri = camel_url_to_string (url, 0);
 	fi->full_name = g_strdup(path);
 	fi->name = g_strdup(base?base+1:path);
Index: camel/providers/local/camel-mbox-store.c
===================================================================
--- camel/providers/local/camel-mbox-store.c	(revision 1044)
+++ camel/providers/local/camel-mbox-store.c	(working copy)
@@ -319,7 +319,7 @@
 	g_free(path);
 	g_free(name);
 	
-	fi = g_new0(CamelFolderInfo, 1);
+	fi = g_slice_new (CamelFolderInfo);
 	fi->full_name = g_strdup(folder_name);
 	fi->name = g_path_get_basename(folder_name);
 	fi->uri = g_strdup_printf("mbox:%s#%s",((CamelService *) store)->url->path, folder_name);
@@ -694,7 +694,7 @@
 				fi->flags &= ~CAMEL_FOLDER_NOSELECT;
 			}
 		} else {
-			fi = g_new0(CamelFolderInfo, 1);
+			fi = g_slice_new (CamelFolderInfo);
 			fi->parent = parent;
 			
 			camel_url_set_fragment (url, full_name);
@@ -803,7 +803,7 @@
 	url = camel_url_copy (((CamelService *) store)->url);
 	camel_url_set_fragment (url, top);
 	
-	fi = g_new0(CamelFolderInfo, 1);
+	fi = g_slice_new (CamelFolderInfo);
 	fi->parent = NULL;
 	fi->uri = camel_url_to_string (url, 0);
 	fi->name = basename;
Index: camel/providers/local/camel-local-folder.c
===================================================================
--- camel/providers/local/camel-local-folder.c	(revision 1044)
+++ camel/providers/local/camel-local-folder.c	(working copy)
@@ -309,7 +309,7 @@
 		url = camel_url_copy (((CamelService *) parent_store)->url);
 		camel_url_set_fragment (url, full_name);
 	
-		fi = g_new0 (CamelFolderInfo, 1);
+		fi = g_slice_new (CamelFolderInfo);
 		fi->full_name = g_strdup (full_name);
 		fi->name = g_strdup (name);
 		fi->uri = camel_url_to_string (url, 0);
Index: camel/providers/local/camel-maildir-store.c
===================================================================
--- camel/providers/local/camel-maildir-store.c	(revision 1044)
+++ camel/providers/local/camel-maildir-store.c	(working copy)
@@ -365,7 +365,7 @@
 	char *tmp, *cur, *new;
 	struct stat st;
 
-	fi = g_malloc0(sizeof(*fi));
+	fi = g_slice_new (CamelFolderInfo);
 	fi->full_name = g_strdup(full);
 	fi->name = g_strdup(name);
 	camel_url_set_fragment(url, fi->full_name);
Index: camel/camel-vee-store.c
===================================================================
--- camel/camel-vee-store.c	(revision 1044)
+++ camel/camel-vee-store.c	(working copy)
@@ -146,7 +146,7 @@
 	const char *tmp;
 	CamelURL *url;
 
-	fi = g_malloc0(sizeof(*fi));
+	fi = g_slice_new (CamelFolderInfo);
 	fi->full_name = g_strdup(name);
 	tmp = strrchr(name, '/');
 	if (tmp == NULL)


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