[pygobject] Avoid O(n^2) behavior when marshalling lists
- From: Paolo Borelli <pborelli src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pygobject] Avoid O(n^2) behavior when marshalling lists
- Date: Wed, 4 Jan 2012 14:37:20 +0000 (UTC)
commit 2bee4207ab6f07dc9c0952affe72f0e304cfb624
Author: Paolo Borelli <pborelli gnome org>
Date: Wed Jan 4 15:24:13 2012 +0100
Avoid O(n^2) behavior when marshalling lists
Appending requires walking the list every time: just prepend and reverse
the list at the end.
https://bugzilla.gnome.org/show_bug.cgi?id=667261
gi/pygi-marshal-from-py.c | 8 ++++----
1 files changed, 4 insertions(+), 4 deletions(-)
---
diff --git a/gi/pygi-marshal-from-py.c b/gi/pygi-marshal-from-py.c
index 3b3109c..4de874b 100644
--- a/gi/pygi-marshal-from-py.c
+++ b/gi/pygi-marshal-from-py.c
@@ -959,7 +959,7 @@ _pygi_marshal_from_py_glist (PyGIInvokeState *state,
&item))
goto err;
- list_ = g_list_append (list_, item.v_pointer);
+ list_ = g_list_prepend (list_, item.v_pointer);
continue;
err:
/* FIXME: clean up list
@@ -972,7 +972,7 @@ err:
return FALSE;
}
- arg->v_pointer = list_;
+ arg->v_pointer = g_list_reverse (list_);
return TRUE;
}
@@ -1026,7 +1026,7 @@ _pygi_marshal_from_py_gslist (PyGIInvokeState *state,
&item))
goto err;
- list_ = g_slist_append (list_, item.v_pointer);
+ list_ = g_slist_prepend (list_, item.v_pointer);
continue;
err:
/* FIXME: Clean up list
@@ -1040,7 +1040,7 @@ err:
return FALSE;
}
- arg->v_pointer = list_;
+ arg->v_pointer = g_slist_reverse (list_);
return TRUE;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]