Re: [Evolution-hackers] [evolution-patches] Fix for "agressive" memory segmentation



For some strange reason I thought the pstring stuff already did that,
oops. I guess I was thinking of similar code I wrote a few years back
for another project...

This patch does it the way I had done it in another project of mine

On Thu, 2006-07-06 at 20:31 +0200, Philip Van Hoof wrote:
> Camel makes some "aggressive" memory segmentation happen when loading
> the folder summary.
> 
> This fixes that.
> 
> This is NOT yet the mmap() idea. That will come later.
> 
> 
> _______________________________________________
> Evolution-patches mailing list
> Evolution-patches gnome org
> http://mail.gnome.org/mailman/listinfo/evolution-patches
-- 
Jeffrey Stedfast
Evolution Hacker - Novell, Inc.
fejj novell com  - www.novell.com
? 340717.patch
? camel-mime-tables.c
? pstring.patch
? providers/imap/camel-imap-private.h
? providers/local/mbox-repair.patch
? providers/smtp/336035.patch
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/evolution-data-server/camel/ChangeLog,v
retrieving revision 1.2526.2.10
diff -u -r1.2526.2.10 ChangeLog
--- ChangeLog	15 Jun 2006 20:51:50 -0000	1.2526.2.10
+++ ChangeLog	6 Jul 2006 19:18:34 -0000
@@ -1,3 +1,18 @@
+2006-07-06  Jeffrey Stedfast  <fejj novell com>
+
+	* camel-string-utils.c (camel_pstring_add): New function that now
+	holds the main logic of the old camel_pstring_strdup function. If
+	'own' is TRUE, re-use the memory if the string doesn't already
+	exist and free it otherwise. If FALSE, strdup the value if it
+	doesn't already exist.
+	(camel_pstring_strdup): Calls camel_pstring_add() with 'own' as
+	FALSE.
+
+	* camel-folder-summary.c (message_info_new_from_header): Use
+	camel_pstring_add instead of camel_pstring_strdup here to prevent
+	unnecessary strdup/freeing.
+	(message_info_load): Same.
+
 2006-06-15  Tor Lillqvist  <tml novell com>
 
 	* camel.c (camel_init): On Win32, NSS wants the directory name in
Index: camel-folder-summary.c
===================================================================
RCS file: /cvs/gnome/evolution-data-server/camel/camel-folder-summary.c,v
retrieving revision 1.147.2.2
diff -u -r1.147.2.2 camel-folder-summary.c
--- camel-folder-summary.c	13 Apr 2006 19:57:55 -0000	1.147.2.2
+++ camel-folder-summary.c	6 Jul 2006 19:18:34 -0000
@@ -1624,19 +1624,13 @@
 
 	if (ct)
 		camel_content_type_unref(ct);
-
-	mi->subject = camel_pstring_strdup(subject);
-	mi->from = camel_pstring_strdup(from);
-	mi->to = camel_pstring_strdup(to);
-	mi->cc = camel_pstring_strdup(cc);
-	mi->mlist = camel_pstring_strdup(mlist);
-
-	g_free(subject);
-	g_free(from);
-	g_free(to);
-	g_free(cc);
-	g_free(mlist);
-
+	
+	mi->subject = camel_pstring_add (subject, TRUE);
+	mi->from = camel_pstring_add (from, TRUE);
+	mi->to = camel_pstring_add (to, TRUE);
+	mi->cc = camel_pstring_add (cc, TRUE);
+	mi->mlist = camel_pstring_add (mlist, TRUE);
+	
 	mi->user_flags = NULL;
 	mi->user_tags = NULL;
 	mi->date_sent = camel_header_decode_date(camel_header_raw_find(&h, "date", NULL), NULL);
@@ -1709,20 +1703,14 @@
 	camel_file_util_decode_string(in, &to);
 	camel_file_util_decode_string(in, &cc);
 	camel_file_util_decode_string(in, &mlist);
-
+	
 	mi->uid = uid;
-	mi->subject = camel_pstring_strdup(subject);
-	mi->from = camel_pstring_strdup(from);
-	mi->to = camel_pstring_strdup(to);
-	mi->cc = camel_pstring_strdup(cc);
-	mi->mlist = camel_pstring_strdup(mlist);
-
-	g_free(subject);
-	g_free(from);
-	g_free(to);
-	g_free(cc);
-	g_free(mlist);
-
+	mi->subject = camel_pstring_add (subject, TRUE);
+	mi->from = camel_pstring_add (from, TRUE);
+	mi->to = camel_pstring_add (to, TRUE);
+	mi->cc = camel_pstring_add (cc, TRUE);
+	mi->mlist = camel_pstring_add (mlist, TRUE);
+	
 	mi->content = NULL;
 
 	camel_file_util_decode_fixed_int32(in, &mi->message_id.id.part.hi);
Index: camel-string-utils.c
===================================================================
RCS file: /cvs/gnome/evolution-data-server/camel/camel-string-utils.c,v
retrieving revision 1.5
diff -u -r1.5 camel-string-utils.c
--- camel-string-utils.c	15 Sep 2005 17:35:45 -0000	1.5
+++ camel-string-utils.c	6 Jul 2006 19:18:34 -0000
@@ -146,46 +146,72 @@
 static GHashTable *pstring_table = NULL;
 
 /**
- * camel_pstring_strdup:
- * @s: String to copy.
- * 
- * Create a new pooled string entry for the string @s.  A pooled
- * string is a table where common strings are uniquified to the same
- * pointer value.  They are also refcounted, so freed when no longer
- * in use.  In a thread-safe manner.
- * 
+ * camel_pstring_add:
+ * @str: string to add to the string pool
+ * @own: whether the string pool will own the memory pointed to by @s if @str is not yet in the pool
+ *
+ * Add the string to the pool.
+ *
  * The NULL and empty strings are special cased to constant values.
  *
  * Return value: A pointer to an equivalent string of @s.  Use
  * camel_pstring_free() when it is no longer needed.
  **/
-const char *camel_pstring_strdup(const char *s)
+const char *
+camel_pstring_add (char *str, gboolean own)
 {
-	char *p;
 	void *pcount;
+	char *pstr;
 	int count;
-
+	
 	if (s == NULL)
 		return NULL;
-	if (s[0] == 0)
+	
+	if (s[0] == '\0') {
+		if (own)
+			g_free (str);
 		return "";
-
-	pthread_mutex_lock(&pstring_lock);
+	}
+	
+	pthread_mutex_lock (&pstring_lock);
 	if (pstring_table == NULL)
-		pstring_table = g_hash_table_new(g_str_hash, g_str_equal);
-
-	if (g_hash_table_lookup_extended(pstring_table, s, (void **)&p, &pcount)) {
-		count = GPOINTER_TO_INT(pcount)+1;
-		g_hash_table_insert(pstring_table, p, GINT_TO_POINTER(count));
+		pstring_table = g_hash_table_new (g_str_hash, g_str_equal);
+	
+	if (g_hash_table_lookup_extended (pstring_table, str, (void **) &pstr, &pcount)) {
+		count = GPOINTER_TO_INT (pcount) + 1;
+		g_hash_table_insert (pstring_table, pstr, GINT_TO_POINTER (count));
 	} else {
-		p = g_strdup(s);
-		g_hash_table_insert(pstring_table, p, GINT_TO_POINTER(1));
+		pstr = own ? str : g_strdup (str);
+		g_hash_table_insert (pstring_table, pstr, GINT_TO_POINTER (1));
 	}
-	pthread_mutex_unlock(&pstring_lock);
+	
+	pthread_mutex_unlock (&pstring_lock);
+	
+	return pstr;
+}
+
 
-	return p;
+/**
+ * camel_pstring_strdup:
+ * @s: String to copy.
+ * 
+ * Create a new pooled string entry for the string @s.  A pooled
+ * string is a table where common strings are uniquified to the same
+ * pointer value.  They are also refcounted, so freed when no longer
+ * in use.  In a thread-safe manner.
+ * 
+ * The NULL and empty strings are special cased to constant values.
+ *
+ * Return value: A pointer to an equivalent string of @s.  Use
+ * camel_pstring_free() when it is no longer needed.
+ **/
+const char *
+camel_pstring_strdup (const char *s)
+{
+	return camel_pstring_add ((char *) s, FALSE);
 }
 
+
 /**
  * camel_pstring_free:
  * @s: String to free.
@@ -194,7 +220,8 @@
  *
  * NULL and the empty string are special cased.
  **/
-void camel_pstring_free(const char *s)
+void
+camel_pstring_free(const char *s)
 {
 	char *p;
 	void *pcount;
Index: camel-string-utils.h
===================================================================
RCS file: /cvs/gnome/evolution-data-server/camel/camel-string-utils.h,v
retrieving revision 1.5
diff -u -r1.5 camel-string-utils.h
--- camel-string-utils.h	31 Aug 2005 04:21:56 -0000	1.5
+++ camel-string-utils.h	6 Jul 2006 19:18:34 -0000
@@ -42,6 +42,7 @@
 char camel_tolower(char c);
 char camel_toupper(char c);
 
+const char *camel_pstring_add (char *str, gboolean own);
 const char *camel_pstring_strdup(const char *s);
 void camel_pstring_free(const char *s);
 


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