[evolution-data-server] imapx_parse_uids: Return a GArray instead of a GPtrArray.
- From: Matthew Barnes <mbarnes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-data-server] imapx_parse_uids: Return a GArray instead of a GPtrArray.
- Date: Fri, 4 Oct 2013 15:29:26 +0000 (UTC)
commit ab9a4f422a6ade26eef982496c130daf1d47ba80
Author: Matthew Barnes <mbarnes redhat com>
Date: Fri Oct 4 11:16:05 2013 -0400
imapx_parse_uids: Return a GArray instead of a GPtrArray.
GArray is better for packing integer values. The UIDs are 32 bits,
so this is actually a little more memory efficient on 64-bit systems.
camel/camel-imapx-server.c | 39 ++++++++++++++++++++++--------------
camel/camel-imapx-utils.c | 47 ++++++++++++++++++-------------------------
camel/camel-imapx-utils.h | 6 ++--
3 files changed, 47 insertions(+), 45 deletions(-)
---
diff --git a/camel/camel-imapx-server.c b/camel/camel-imapx-server.c
index 09c422e..b046f56 100644
--- a/camel/camel-imapx-server.c
+++ b/camel/camel-imapx-server.c
@@ -1531,7 +1531,7 @@ imapx_untagged_vanished (CamelIMAPXServer *is,
GError **error)
{
CamelFolder *folder;
- GPtrArray *uids = NULL;
+ GArray *uids;
GList *uid_list = NULL;
gboolean unsolicited = TRUE;
guint ii = 0;
@@ -1583,16 +1583,16 @@ imapx_untagged_vanished (CamelIMAPXServer *is,
is->priv->changes = camel_folder_change_info_new ();
for (ii = 0; ii < uids->len; ii++) {
- gpointer data;
- gchar *uid;
+ guint32 uid;
+ gchar *str;
- data = g_ptr_array_index (uids, ii);
- uid = g_strdup_printf ("%u", GPOINTER_TO_UINT (data));
+ uid = g_array_index (uids, guint32, ii);
- c (is->tagprefix, "vanished: %s\n", uid);
+ c (is->tagprefix, "vanished: %u\n", uid);
- uid_list = g_list_prepend (uid_list, uid);
- camel_folder_change_info_remove_uid (is->priv->changes, uid);
+ str = g_strdup_printf ("%u", uid);
+ uid_list = g_list_prepend (uid_list, str);
+ camel_folder_change_info_remove_uid (is->priv->changes, str);
}
uid_list = g_list_reverse (uid_list);
@@ -1608,7 +1608,7 @@ imapx_untagged_vanished (CamelIMAPXServer *is,
}
g_list_free_full (uid_list, (GDestroyNotify) g_free);
- g_ptr_array_free (uids, TRUE);
+ g_array_free (uids, TRUE);
g_object_unref (folder);
@@ -4593,14 +4593,23 @@ imapx_command_copy_messages_step_done (CamelIMAPXServer *is,
* We might need a sorted insert to avoid refreshing the dest
* folder. */
if (ic->status && ic->status->condition == IMAPX_COPYUID) {
- gint i;
+ CamelIMAPXFolder *dest;
+ GArray *array;
+ guint ii;
+
+ dest = CAMEL_IMAPX_FOLDER (data->dest);
+ array = ic->status->u.copyuid.copied_uids;
+
+ for (ii = 0; ii < array->len; ii++) {
+ guint32 uid;
+ gchar *str;
- for (i = 0; i < ic->status->u.copyuid.copied_uids->len; i++) {
- guint32 uid = GPOINTER_TO_UINT (g_ptr_array_index (ic->status->u.copyuid.copied_uids,
i));
- gchar *str = g_strdup_printf ("%d",uid);
- CamelIMAPXFolder *ifolder = (CamelIMAPXFolder *) data->dest;
+ uid = g_array_index (array, guint32, ii);
+ str = g_strdup_printf ("%u", uid);
- g_hash_table_insert (ifolder->ignore_recent, str, GINT_TO_POINTER (1));
+ g_hash_table_insert (
+ dest->ignore_recent,
+ str, GINT_TO_POINTER (1));
}
}
diff --git a/camel/camel-imapx-utils.c b/camel/camel-imapx-utils.c
index b49563a..e7d2acf 100644
--- a/camel/camel-imapx-utils.c
+++ b/camel/camel-imapx-utils.c
@@ -1961,53 +1961,46 @@ exit:
return finfo;
}
-static void
-generate_uids_from_sequence (GPtrArray *uids,
- guint32 begin_uid,
- guint32 end_uid)
-{
- guint32 i;
-
- for (i = begin_uid; i <= end_uid; i++)
- g_ptr_array_add (uids, GUINT_TO_POINTER (i));
-}
-
-GPtrArray *
+GArray *
imapx_parse_uids (CamelIMAPXStream *is,
GCancellable *cancellable,
GError **error)
{
- GPtrArray *uids;
+ GArray *array;
guchar *token;
gchar **splits;
guint len, str_len;
- gint tok, i;
+ gint tok, ii;
tok = camel_imapx_stream_token (is, &token, &len, cancellable, error);
if (tok < 0)
return NULL;
- uids = g_ptr_array_new ();
+ array = g_array_new (FALSE, FALSE, sizeof (guint32));
splits = g_strsplit ((gchar *) token, ",", -1);
str_len = g_strv_length (splits);
- for (i = 0; i < str_len; i++) {
- if (g_strstr_len (splits[i], -1, ":")) {
- gchar **seq = g_strsplit (splits[i], ":", -1);
- guint32 uid1 = strtoul ((gchar *) seq[0], NULL, 10);
- guint32 uid2 = strtoul ((gchar *) seq[1], NULL, 10);
+ for (ii = 0; ii < str_len; ii++) {
+ guint32 uid;
+
+ if (g_strstr_len (splits[ii], -1, ":")) {
+ gchar **seq = g_strsplit (splits[ii], ":", -1);
+ guint32 first = strtoul (seq[0], NULL, 10);
+ guint32 last = strtoul (seq[1], NULL, 10);
+
+ for (uid = first; uid <= last; uid++)
+ g_array_append_val (array, uid);
- generate_uids_from_sequence (uids, uid1, uid2);
g_strfreev (seq);
} else {
- guint32 uid = strtoul ((gchar *) splits[i], NULL, 10);
- g_ptr_array_add (uids, GUINT_TO_POINTER (uid));
+ uid = strtoul (splits[ii], NULL, 10);
+ g_array_append_val (array, uid);
}
}
g_strfreev (splits);
- return uids;
+ return array;
}
static gboolean
@@ -2048,7 +2041,7 @@ imapx_parse_status_copyuid (CamelIMAPXStream *is,
GCancellable *cancellable,
GError **error)
{
- GPtrArray *uids;
+ GArray *uids;
guint64 number;
if (!camel_imapx_stream_number (is, &number, cancellable, error))
@@ -2371,8 +2364,8 @@ imapx_free_status (struct _status_info *sinfo)
g_free (sinfo->u.newname.newname);
break;
case IMAPX_COPYUID:
- g_ptr_array_free (sinfo->u.copyuid.uids, FALSE);
- g_ptr_array_free (sinfo->u.copyuid.copied_uids, FALSE);
+ g_array_free (sinfo->u.copyuid.uids, TRUE);
+ g_array_free (sinfo->u.copyuid.copied_uids, TRUE);
break;
case IMAPX_CAPABILITY:
if (sinfo->u.cinfo)
diff --git a/camel/camel-imapx-utils.h b/camel/camel-imapx-utils.h
index a57de22..1729866 100644
--- a/camel/camel-imapx-utils.h
+++ b/camel/camel-imapx-utils.h
@@ -135,7 +135,7 @@ enum {
/* ********************************************************************** */
-GPtrArray * imapx_parse_uids (struct _CamelIMAPXStream *is,
+GArray * imapx_parse_uids (struct _CamelIMAPXStream *is,
GCancellable *cancellable,
GError **error);
gboolean imapx_parse_flags (struct _CamelIMAPXStream *is,
@@ -293,8 +293,8 @@ struct _status_info {
} appenduid;
struct {
guint64 uidvalidity;
- GPtrArray *uids;
- GPtrArray *copied_uids;
+ GArray *uids;
+ GArray *copied_uids;
} copyuid;
struct _capability_info *cinfo;
} u;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]