From 61de55bf496c1edb120e4d096140eb1125552bbe Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sat, 24 Nov 2018 01:45:58 -0500 Subject: [PATCH] [arrays] Port hb_vector_t.qsort() to hb_array_t's --- src/hb-dsalgs.hh | 16 +++++++++++++--- src/hb-vector.hh | 10 ++-------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/hb-dsalgs.hh b/src/hb-dsalgs.hh index e66f2b4ca..ef030732a 100644 --- a/src/hb-dsalgs.hh +++ b/src/hb-dsalgs.hh @@ -572,6 +572,10 @@ struct hb_array_t return arrayZ[i]; } + template inline operator T * (void) const { return arrayZ; } + + inline Type * operator & (void) const { return arrayZ; } + inline unsigned int get_size (void) const { return len * sizeof (Type); } template @@ -595,9 +599,15 @@ struct hb_array_t return not_found; } - template inline operator T * (void) const { return arrayZ; } - - inline Type * operator & (void) const { return arrayZ; } + inline void qsort (int (*cmp)(const void*, const void*)) + { + ::qsort (arrayZ, len, sizeof (Type), cmp); + } + inline void qsort (unsigned int start = 0, unsigned int end = (unsigned int) -1) + { + end = MIN (end, len); + ::qsort (arrayZ + start, end - start, sizeof (Type), Type::cmp); + } inline hb_array_t sub_array (unsigned int start_offset, unsigned int seg_count) const { diff --git a/src/hb-vector.hh b/src/hb-vector.hh index a5fa4142b..a8c98d221 100644 --- a/src/hb-vector.hh +++ b/src/hb-vector.hh @@ -221,15 +221,9 @@ struct hb_vector_t } inline void qsort (int (*cmp)(const void*, const void*)) - { - ::qsort (arrayZ(), len, sizeof (Type), cmp); - } - + { as_array ().qsort (cmp); } inline void qsort (unsigned int start = 0, unsigned int end = (unsigned int) -1) - { - end = MIN (end, len); - ::qsort (arrayZ() + start, end - start, sizeof (Type), Type::cmp); - } + { as_array ().qsort (start, end); } template inline Type *lsearch (const T &x, Type *not_found = nullptr)