[vector/array] Simplify qsort()

This commit is contained in:
Behdad Esfahbod 2022-11-16 21:21:31 -07:00
parent 1610008e62
commit c7d57dcf26
4 changed files with 4 additions and 13 deletions

View File

@ -194,13 +194,6 @@ struct hb_array_t : hb_iter_with_fallback_t<hb_array_t<Type>, Type&>
hb_qsort (arrayZ, length, this->get_item_size (), Type::cmp); hb_qsort (arrayZ, length, this->get_item_size (), Type::cmp);
return hb_sorted_array_t<Type> (*this); return hb_sorted_array_t<Type> (*this);
} }
void qsort (unsigned int start, unsigned int end)
{
end = hb_min (end, length);
assert (start <= end);
if (likely (start < end))
hb_qsort (arrayZ + start, end - start, this->get_item_size (), Type::cmp);
}
/* /*
* Other methods. * Other methods.

View File

@ -667,8 +667,8 @@ struct ArrayOf
unsigned int to_store = (unsigned int) -1) const unsigned int to_store = (unsigned int) -1) const
{ return as_array ().lfind (x, i, not_found, to_store); } { return as_array ().lfind (x, i, not_found, to_store); }
void qsort (unsigned int start = 0, unsigned int end = (unsigned int) -1) void qsort ()
{ as_array ().qsort (start, end); } { as_array ().qsort (); }
HB_NODISCARD bool serialize (hb_serialize_context_t *c, unsigned items_len) HB_NODISCARD bool serialize (hb_serialize_context_t *c, unsigned items_len)
{ {

View File

@ -343,7 +343,7 @@ hb_ot_map_builder_t::compile (hb_ot_map_t &m,
/* Sort lookups and merge duplicates */ /* Sort lookups and merge duplicates */
if (last_num_lookups < m.lookups[table_index].length) if (last_num_lookups < m.lookups[table_index].length)
{ {
m.lookups[table_index].qsort (last_num_lookups, m.lookups[table_index].length); m.lookups[table_index].sub_array (last_num_lookups, m.lookups[table_index].length - last_num_lookups).qsort ();
unsigned int j = last_num_lookups; unsigned int j = last_num_lookups;
for (unsigned int i = j + 1; i < m.lookups[table_index].length; i++) for (unsigned int i = j + 1; i < m.lookups[table_index].length; i++)

View File

@ -425,10 +425,8 @@ struct hb_vector_t
/* Sorting API. */ /* Sorting API. */
void qsort (int (*cmp)(const void*, const void*)) void qsort (int (*cmp)(const void*, const void*) = Type::cmp)
{ as_array ().qsort (cmp); } { as_array ().qsort (cmp); }
void qsort (unsigned int start = 0, unsigned int end = (unsigned int) -1)
{ as_array ().qsort (start, end); }
/* Unsorted search API. */ /* Unsorted search API. */
template <typename T> template <typename T>