[evolution-data-server] Bug #661448 - e_util_copy_*_slist(): Avoid using append function
- From: Christophe Dumez <cdumez src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-data-server] Bug #661448 - e_util_copy_*_slist(): Avoid using append function
- Date: Wed, 12 Oct 2011 09:58:12 +0000 (UTC)
commit 05623005c5be50413e2410525d0b7cc682cda25c
Author: Christophe Dumez <christophe dumez intel com>
Date: Tue Oct 11 14:02:57 2011 +0300
Bug #661448 - e_util_copy_*_slist(): Avoid using append function
The current implementation calls g_slist_append() for each element
of the list to copy. However, g_slist_append() is expensive
because it iterate over the whole destination list.
This patch alters the behavior to first make a deep copy of the
list and then concatenate the destination list and the list copy.
The concatenation only iterates of the destination list once.
libedataserver/e-data-server-util.c | 32 ++++++++++++++++++++------------
1 files changed, 20 insertions(+), 12 deletions(-)
---
diff --git a/libedataserver/e-data-server-util.c b/libedataserver/e-data-server-util.c
index 764fa09..94d2177 100644
--- a/libedataserver/e-data-server-util.c
+++ b/libedataserver/e-data-server-util.c
@@ -870,14 +870,18 @@ GSList *
e_util_copy_string_slist (GSList *copy_to,
const GSList *strings)
{
- GSList *res = copy_to;
- const GSList *iter;
-
- for (iter = strings; iter; iter = iter->next) {
- res = g_slist_append (res, g_strdup (iter->data));
+ if (strings != NULL) {
+ const GSList *iter;
+ GSList *strings_copy = NULL;
+ /* Make deep copy of strings */
+ for (iter = strings; iter; iter = iter->next)
+ strings_copy = g_slist_prepend (strings_copy, g_strdup (iter->data));
+
+ /* Concatenate the two lists */
+ return g_slist_concat (copy_to, g_slist_reverse (strings_copy));
}
- return res;
+ return copy_to;
}
/**
@@ -896,14 +900,18 @@ GSList *
e_util_copy_object_slist (GSList *copy_to,
const GSList *objects)
{
- GSList *res = copy_to;
- const GSList *iter;
-
- for (iter = objects; iter; iter = iter->next) {
- res = g_slist_append (res, g_object_ref (iter->data));
+ if (objects != NULL) {
+ const GSList *iter;
+ GSList *objects_copy = NULL;
+ /* Make deep copy of objects */
+ for (iter = objects; iter; iter = iter->next)
+ objects_copy = g_slist_prepend (objects_copy, g_object_ref (iter->data));
+
+ /* Concatenate the two lists */
+ return g_slist_concat (copy_to, g_slist_reverse (objects_copy));
}
- return res;
+ return copy_to;
}
/**
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]