mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-08-01 23:13:40 +02:00
gqsort: Add g_sort_array() and deprecate g_qsort_with_data()
The latter only accepts a `gint` as the number of elements in the array, which means that its use in `GArray` (and related array implementations) truncates at least half the potential array size. So, introduce a replacement for it which uses `size_t` for the number of elements. This is inline with what `qsort()` (or `qsort_r()`) actually does. Unfortunately we can’t directly use `qsort_r()` because it’s not guaranteed to be a stable sort. This fixes some `-Wsign-conversion` warnings (when building GLib with that enabled). Signed-off-by: Philip Withnall <pwithnall@gnome.org> Helps: #3405
This commit is contained in:
@@ -364,9 +364,9 @@ g_value_array_sort_with_data (GValueArray *value_array,
|
||||
g_return_val_if_fail (compare_func != NULL, NULL);
|
||||
|
||||
if (value_array->n_values)
|
||||
g_qsort_with_data (value_array->values,
|
||||
value_array->n_values,
|
||||
sizeof (value_array->values[0]),
|
||||
compare_func, user_data);
|
||||
g_sort_array (value_array->values,
|
||||
value_array->n_values,
|
||||
sizeof (value_array->values[0]),
|
||||
compare_func, user_data);
|
||||
return value_array;
|
||||
}
|
||||
|
Reference in New Issue
Block a user