[gtk/wip/otte/sortlistmodel: 119/134] sortlistmodel: Make sort stable again
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/otte/sortlistmodel: 119/134] sortlistmodel: Make sort stable again
- Date: Tue, 21 Jul 2020 02:23:04 +0000 (UTC)
commit 74f5a53ae55b42f4f63eea0a16979e9608cacf1d
Author: Benjamin Otte <otte redhat com>
Date: Tue Jul 21 04:06:13 2020 +0200
sortlistmodel: Make sort stable again
Previously, the sort was not stable when items were added/removed while
sorting or the sort algorithm was changed.
Now the sort looks at the item position (via the key's location in the
keys array) to make sure each comparison stays stable with respect to
this position.
gtk/gtksortlistmodel.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
---
diff --git a/gtk/gtksortlistmodel.c b/gtk/gtksortlistmodel.c
index 0b50e575d4..548383b10b 100644
--- a/gtk/gtksortlistmodel.c
+++ b/gtk/gtksortlistmodel.c
@@ -255,7 +255,11 @@ sort_func (gconstpointer a,
gpointer *sb = (gpointer *) b;
int result;
- return gtk_sort_keys_compare (data, *sa, *sb);
+ result = gtk_sort_keys_compare (data, *sa, *sb);
+ if (result)
+ return result;
+
+ return *sa < *sb ? -1 : 1;
}
static gboolean
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]