[gtk/wip/otte/listview: 2033/2170] sortlistmodel: Make sort stable
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/otte/listview: 2033/2170] sortlistmodel: Make sort stable
- Date: Sun, 24 May 2020 17:10:10 +0000 (UTC)
commit 26fe09cbedefb2f749766edd9980a1f711a6fbaa
Author: Benjamin Otte <otte redhat com>
Date: Wed Dec 11 01:22:20 2019 +0100
sortlistmodel: Make sort stable
The sort of the sortlistmodel is now stable with respect to the original
list model.
That means that if the sorter compares items as equal, the model
will make sure those items keep the order they were in in the original
model.
Or in other words: The model guarantees a total order based on the
item's position in the original model.
gtk/gtksortlistmodel.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
---
diff --git a/gtk/gtksortlistmodel.c b/gtk/gtksortlistmodel.c
index 2fa9de9944..5444ee74ae 100644
--- a/gtk/gtksortlistmodel.c
+++ b/gtk/gtksortlistmodel.c
@@ -181,8 +181,14 @@ _sort_func (gconstpointer item1,
{
GtkSortListEntry *entry1 = (GtkSortListEntry *) item1;
GtkSortListEntry *entry2 = (GtkSortListEntry *) item2;
+ GtkOrdering result;
- return gtk_sorter_compare (GTK_SORTER (data), entry1->item, entry2->item);
+ result = gtk_sorter_compare (GTK_SORTER (data), entry1->item, entry2->item);
+
+ if (result == GTK_ORDERING_EQUAL)
+ result = g_sequence_iter_compare (entry1->unsorted_iter, entry2->unsorted_iter);
+
+ return result;
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]