[evolution-data-server] CamelMessageInfo: Cache common strings in the string pool



commit 68e1ab5a3f2944b9e1c7973834519348273fab11
Author: Milan Crha <mcrha redhat com>
Date:   Wed Jan 22 12:04:17 2020 +0100

    CamelMessageInfo: Cache common strings in the string pool
    
    This may save some memory when these values are repeating, for a price
    of possibly slightly slower load/save of the message info data.

 src/camel/camel-db.c                | 10 ++++-----
 src/camel/camel-db.h                | 12 +++++-----
 src/camel/camel-message-info-base.c | 45 +++++++++++++++++--------------------
 src/camel/camel-message-info.c      | 12 +++++-----
 4 files changed, 38 insertions(+), 41 deletions(-)
---
diff --git a/src/camel/camel-db.c b/src/camel/camel-db.c
index 5bf863b1e..154b2a70f 100644
--- a/src/camel/camel-db.c
+++ b/src/camel/camel-db.c
@@ -2563,11 +2563,11 @@ camel_db_camel_mir_free (CamelMIRecord *record)
 {
        if (record) {
                camel_pstring_free (record->uid);
-               g_free (record->subject);
-               g_free (record->from);
-               g_free (record->to);
-               g_free (record->cc);
-               g_free (record->mlist);
+               camel_pstring_free (record->subject);
+               camel_pstring_free (record->from);
+               camel_pstring_free (record->to);
+               camel_pstring_free (record->cc);
+               camel_pstring_free (record->mlist);
                g_free (record->followup_flag);
                g_free (record->followup_completed_on);
                g_free (record->followup_due_by);
diff --git a/src/camel/camel-db.h b/src/camel/camel-db.h
index 42e320500..c40b3ecbe 100644
--- a/src/camel/camel-db.h
+++ b/src/camel/camel-db.h
@@ -166,7 +166,7 @@ typedef gint (* CamelDBCollate)(gpointer enc, gint length1, gconstpointer data1,
  * Since: 2.24
  **/
 typedef struct _CamelMIRecord {
-       gchar *uid;
+       const gchar *uid; /* stored in the string pool */
        guint32 flags;
        guint32 msg_type;
        guint32 dirty;
@@ -179,11 +179,11 @@ typedef struct _CamelMIRecord {
        guint32 size;
        gint64 dsent; /* time_t */
        gint64 dreceived; /* time_t */
-       gchar *subject;
-       gchar *from;
-       gchar *to;
-       gchar *cc;
-       gchar *mlist;
+       const gchar *subject;   /* stored in the string pool */
+       const gchar *from;      /* stored in the string pool */
+       const gchar *to;        /* stored in the string pool */
+       const gchar *cc;        /* stored in the string pool */
+       const gchar *mlist;     /* stored in the string pool */
        gchar *followup_flag;
        gchar *followup_completed_on;
        gchar *followup_due_by;
diff --git a/src/camel/camel-message-info-base.c b/src/camel/camel-message-info-base.c
index e19224ab1..a77e9700a 100644
--- a/src/camel/camel-message-info-base.c
+++ b/src/camel/camel-message-info-base.c
@@ -21,6 +21,7 @@
 
 #include "camel-folder-summary.h"
 #include "camel-message-info.h"
+#include "camel-string-utils.h"
 
 #include "camel-message-info-base.h"
 
@@ -28,11 +29,11 @@ struct _CamelMessageInfoBasePrivate {
        guint32 flags;          /* bit-or of CamelMessageFlags */
        CamelNamedFlags *user_flags;
        CamelNameValueArray *user_tags;
-       gchar *subject;
-       gchar *from;
-       gchar *to;
-       gchar *cc;
-       gchar *mlist;
+       const gchar *subject;   /* stored in the string pool */
+       const gchar *from;      /* stored in the string pool */
+       const gchar *to;        /* stored in the string pool */
+       const gchar *cc;        /* stored in the string pool */
+       const gchar *mlist;     /* stored in the string pool */
        guint32 size;
        gint64 date_sent;       /* aka time_t */
        gint64 date_received;   /* aka time_t */
@@ -335,8 +336,8 @@ message_info_base_set_subject (CamelMessageInfo *mi,
        changed = g_strcmp0 (bmi->priv->subject, subject) != 0;
 
        if (changed) {
-               g_free (bmi->priv->subject);
-               bmi->priv->subject = g_strdup (subject);
+               camel_pstring_free (bmi->priv->subject);
+               bmi->priv->subject = camel_pstring_strdup (subject);
        }
 
        camel_message_info_property_unlock (mi);
@@ -377,8 +378,8 @@ message_info_base_set_from (CamelMessageInfo *mi,
        changed = g_strcmp0 (bmi->priv->from, from) != 0;
 
        if (changed) {
-               g_free (bmi->priv->from);
-               bmi->priv->from = g_strdup (from);
+               camel_pstring_free (bmi->priv->from);
+               bmi->priv->from = camel_pstring_strdup (from);
        }
 
        camel_message_info_property_unlock (mi);
@@ -419,8 +420,8 @@ message_info_base_set_to (CamelMessageInfo *mi,
        changed = g_strcmp0 (bmi->priv->to, to) != 0;
 
        if (changed) {
-               g_free (bmi->priv->to);
-               bmi->priv->to = g_strdup (to);
+               camel_pstring_free (bmi->priv->to);
+               bmi->priv->to = camel_pstring_strdup (to);
        }
 
        camel_message_info_property_unlock (mi);
@@ -461,8 +462,8 @@ message_info_base_set_cc (CamelMessageInfo *mi,
        changed = g_strcmp0 (bmi->priv->cc, cc) != 0;
 
        if (changed) {
-               g_free (bmi->priv->cc);
-               bmi->priv->cc = g_strdup (cc);
+               camel_pstring_free (bmi->priv->cc);
+               bmi->priv->cc = camel_pstring_strdup (cc);
        }
 
        camel_message_info_property_unlock (mi);
@@ -503,8 +504,8 @@ message_info_base_set_mlist (CamelMessageInfo *mi,
        changed = g_strcmp0 (bmi->priv->mlist, mlist) != 0;
 
        if (changed) {
-               g_free (bmi->priv->mlist);
-               bmi->priv->mlist = g_strdup (mlist);
+               camel_pstring_free (bmi->priv->mlist);
+               bmi->priv->mlist = camel_pstring_strdup (mlist);
        }
 
        camel_message_info_property_unlock (mi);
@@ -798,15 +799,11 @@ message_info_base_dispose (GObject *object)
        camel_name_value_array_free (bmi->priv->user_tags);
        bmi->priv->user_tags = NULL;
 
-       #define free_ptr(x) G_STMT_START { g_free (x); x = NULL; } G_STMT_END
-
-       free_ptr (bmi->priv->subject);
-       free_ptr (bmi->priv->from);
-       free_ptr (bmi->priv->to);
-       free_ptr (bmi->priv->cc);
-       free_ptr (bmi->priv->mlist);
-
-       #undef free_ptr
+       g_clear_pointer (&bmi->priv->subject, (GDestroyNotify) camel_pstring_free);
+       g_clear_pointer (&bmi->priv->from, (GDestroyNotify) camel_pstring_free);
+       g_clear_pointer (&bmi->priv->to, (GDestroyNotify) camel_pstring_free);
+       g_clear_pointer (&bmi->priv->cc, (GDestroyNotify) camel_pstring_free);
+       g_clear_pointer (&bmi->priv->mlist, (GDestroyNotify) camel_pstring_free);
 
        if (bmi->priv->references) {
                g_array_unref (bmi->priv->references);
diff --git a/src/camel/camel-message-info.c b/src/camel/camel-message-info.c
index d26232100..70e4bedc9 100644
--- a/src/camel/camel-message-info.c
+++ b/src/camel/camel-message-info.c
@@ -267,7 +267,7 @@ message_info_save (const CamelMessageInfo *mi,
        g_return_val_if_fail (record != NULL, FALSE);
        g_return_val_if_fail (bdata_str != NULL, FALSE);
 
-       record->uid = (gchar *) camel_pstring_strdup (camel_message_info_get_uid (mi));
+       record->uid = camel_pstring_strdup (camel_message_info_get_uid (mi));
        record->flags = camel_message_info_get_flags (mi);
 
        if ((record->flags & CAMEL_MESSAGE_JUNK) != 0) {
@@ -302,11 +302,11 @@ message_info_save (const CamelMessageInfo *mi,
        record->dsent = camel_message_info_get_date_sent (mi);
        record->dreceived = camel_message_info_get_date_received (mi);
 
-       record->subject = g_strdup (camel_message_info_get_subject (mi));
-       record->from = g_strdup (camel_message_info_get_from (mi));
-       record->to = g_strdup (camel_message_info_get_to (mi));
-       record->cc = g_strdup (camel_message_info_get_cc (mi));
-       record->mlist = g_strdup (camel_message_info_get_mlist (mi));
+       record->subject = camel_pstring_strdup (camel_message_info_get_subject (mi));
+       record->from = camel_pstring_strdup (camel_message_info_get_from (mi));
+       record->to = camel_pstring_strdup (camel_message_info_get_to (mi));
+       record->cc = camel_pstring_strdup (camel_message_info_get_cc (mi));
+       record->mlist = camel_pstring_strdup (camel_message_info_get_mlist (mi));
 
        record->followup_flag = g_strdup (camel_message_info_get_user_tag (mi, "follow-up"));
        record->followup_completed_on = g_strdup (camel_message_info_get_user_tag (mi, "completed-on"));


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