[evolution-data-server] Speed-up e_contact_get_attributes_set()
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-data-server] Speed-up e_contact_get_attributes_set()
- Date: Tue, 21 Jan 2020 18:08:55 +0000 (UTC)
commit d37dc62901cbcfc49221a62d7e8ce31d1c03b9fa
Author: Milan Crha <mcrha redhat com>
Date: Tue Jan 21 16:29:07 2020 +0100
Speed-up e_contact_get_attributes_set()
by using GHashTable for field check for existence.
src/addressbook/libebook-contacts/e-contact.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
---
diff --git a/src/addressbook/libebook-contacts/e-contact.c b/src/addressbook/libebook-contacts/e-contact.c
index 9b26799f3..5b00d1b17 100644
--- a/src/addressbook/libebook-contacts/e-contact.c
+++ b/src/addressbook/libebook-contacts/e-contact.c
@@ -37,6 +37,9 @@
#include <string.h>
#include <gio/gio.h>
#include <glib/gi18n-lib.h>
+
+#include "camel/camel.h"
+
#include "e-contact.h"
#include "e-name-western.h"
@@ -2079,16 +2082,18 @@ e_contact_get_attributes_set (EContact *contact,
GList *l = NULL;
GList *attrs, *a;
gint ii;
- EContactFieldInfo **infos;
+ GHashTable *field_names;
g_return_val_if_fail (contact && E_IS_CONTACT (contact), NULL);
g_return_val_if_fail (size > 0, NULL);
g_return_val_if_fail (size < E_CONTACT_FIELD_LAST, NULL);
- infos = g_new0 (EContactFieldInfo *, size);
+ field_names = g_hash_table_new (camel_strcase_hash, camel_strcase_equal);
+
for (ii = 0; ii < size; ii++) {
g_return_val_if_fail (field_ids[ii] >= 1 && field_ids[ii] < E_CONTACT_FIELD_LAST, NULL);
- infos[ii] = (EContactFieldInfo *) &field_info[field_ids[ii]];
+
+ g_hash_table_insert (field_names, (gpointer) field_info[field_ids[ii]].vcard_field_name,
NULL);
}
attrs = e_vcard_get_attributes (E_VCARD (contact));
@@ -2099,15 +2104,11 @@ e_contact_get_attributes_set (EContact *contact,
name = e_vcard_attribute_get_name (attr);
- for (ii = 0; ii < size; ii++) {
- if (!g_ascii_strcasecmp (name, infos[ii]->vcard_field_name)) {
- l = g_list_prepend (l, e_vcard_attribute_copy (attr));
- break;
- }
- }
+ if (name && g_hash_table_contains (field_names, name))
+ l = g_list_prepend (l, e_vcard_attribute_copy (attr));
}
- g_free (infos);
+ g_hash_table_destroy (field_names);
return g_list_reverse (l);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]