diff options
author | Benjamin Otte <otte@redhat.com> | 2020-07-21 04:06:13 +0200 |
---|---|---|
committer | Benjamin Otte <otte@redhat.com> | 2020-07-22 14:30:49 +0200 |
commit | c03383d3e5796e00ff167a44fdc5b0ff88bedf49 (patch) | |
tree | 96ce1f9a11622f5cfbd355dab509e72bfa7e43cc /gtk/gtksortlistmodel.c | |
parent | eaaa287078e00860b46f4013157a532381437975 (diff) | |
download | gtk+-c03383d3e5796e00ff167a44fdc5b0ff88bedf49.tar.gz |
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.
Diffstat (limited to 'gtk/gtksortlistmodel.c')
-rw-r--r-- | gtk/gtksortlistmodel.c | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/gtk/gtksortlistmodel.c b/gtk/gtksortlistmodel.c index 37dcd6f18e..5fa3105323 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 |