[pango/tab-speedup: 1/4] Add pango_tab_array_sort
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pango/tab-speedup: 1/4] Add pango_tab_array_sort
- Date: Thu, 2 Dec 2021 04:34:19 +0000 (UTC)
commit 0a1c31901fbf0db9e98b02ad3ba02681f1c31774
Author: Matthias Clasen <mclasen redhat com>
Date: Wed Dec 1 23:03:28 2021 -0500
Add pango_tab_array_sort
A utility function to ensure tab stops are in
increasing order.
pango/pango-tabs.c | 25 +++++++++++++++++++++++++
pango/pango-tabs.h | 3 +++
2 files changed, 28 insertions(+)
---
diff --git a/pango/pango-tabs.c b/pango/pango-tabs.c
index 27ae3be8..0665161c 100644
--- a/pango/pango-tabs.c
+++ b/pango/pango-tabs.c
@@ -576,3 +576,28 @@ pango_tab_array_get_decimal_point (PangoTabArray *tab_array,
return tab_array->tabs[tab_index].decimal_point;
}
+
+static int
+compare_tabs (const void *p1, const void *p2)
+{
+ const PangoTab *t1 = p1;
+ const PangoTab *t2 = p2;
+
+ return t1->location - t2->location;
+}
+
+/**
+ * pango_tab_array_sort:
+ * @tab_array: a `PangoTabArray`
+ *
+ * Utility function to ensure that the tab stops are in increasing order.
+ *
+ * Since: 1.50
+ */
+void
+pango_tab_array_sort (PangoTabArray *tab_array)
+{
+ g_return_if_fail (tab_array != NULL);
+
+ qsort (tab_array->tabs, tab_array->size, sizeof (PangoTab), compare_tabs);
+}
diff --git a/pango/pango-tabs.h b/pango/pango-tabs.h
index 0792a36a..8ca94fdb 100644
--- a/pango/pango-tabs.h
+++ b/pango/pango-tabs.h
@@ -106,6 +106,9 @@ PANGO_AVAILABLE_IN_1_50
gunichar pango_tab_array_get_decimal_point (PangoTabArray *tab_array,
int tab_index);
+PANGO_AVAILABLE_IN_1_50
+void pango_tab_array_sort (PangoTabArray *tab_array);
+
G_DEFINE_AUTOPTR_CLEANUP_FUNC(PangoTabArray, pango_tab_array_free)
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]