diff --git a/src/hb-dsalgs.hh b/src/hb-dsalgs.hh index 958687194..68b1fd111 100644 --- a/src/hb-dsalgs.hh +++ b/src/hb-dsalgs.hh @@ -158,4 +158,55 @@ static inline void hb_sort_r(void *base, size_t nel, size_t width, sort_r_simple(base, nel, width, compar, arg); } + +template static inline void +hb_stable_sort (T *array, unsigned int len, int(*compar)(const T *, const T *), T2 *array2) +{ + for (unsigned int i = 1; i < len; i++) + { + unsigned int j = i; + while (j && compar (&array[j - 1], &array[i]) > 0) + j--; + if (i == j) + continue; + /* Move item i to occupy place for item j, shift what's in between. */ + { + T t = array[i]; + memmove (&array[j + 1], &array[j], (i - j) * sizeof (T)); + array[j] = t; + } + if (array2) + { + T2 t = array2[i]; + memmove (&array2[j + 1], &array2[j], (i - j) * sizeof (T2)); + array2[j] = t; + } + } +} + +template static inline void +hb_stable_sort (T *array, unsigned int len, int(*compar)(const T *, const T *)) +{ + hb_stable_sort (array, len, compar, (int *) nullptr); +} + +static inline hb_bool_t +hb_codepoint_parse (const char *s, unsigned int len, int base, hb_codepoint_t *out) +{ + /* Pain because we don't know whether s is nul-terminated. */ + char buf[64]; + len = MIN (ARRAY_LENGTH (buf) - 1, len); + strncpy (buf, s, len); + buf[len] = '\0'; + + char *end; + errno = 0; + unsigned long v = strtoul (buf, &end, base); + if (errno) return false; + if (*end) return false; + *out = v; + return true; +} + + #endif /* HB_DSALGS_HH */ diff --git a/src/hb-ot-os2-unicode-ranges.hh b/src/hb-ot-os2-unicode-ranges.hh index 9b32cfabb..cb1260784 100644 --- a/src/hb-ot-os2-unicode-ranges.hh +++ b/src/hb-ot-os2-unicode-ranges.hh @@ -28,7 +28,6 @@ #define HB_OT_OS2_UNICODE_RANGES_HH #include "hb-private.hh" -#include "hb-dsalgs.hh" namespace OT { diff --git a/src/hb-ot-post-table.hh b/src/hb-ot-post-table.hh index 5f42751d8..d05fc091c 100644 --- a/src/hb-ot-post-table.hh +++ b/src/hb-ot-post-table.hh @@ -28,7 +28,6 @@ #define HB_OT_POST_TABLE_HH #include "hb-open-type-private.hh" -#include "hb-dsalgs.hh" #include "hb-subset-plan.hh" #define HB_STRING_ARRAY_NAME format1_names diff --git a/src/hb-private.hh b/src/hb-private.hh index c4fae17b6..49ce6fef6 100644 --- a/src/hb-private.hh +++ b/src/hb-private.hh @@ -1059,55 +1059,6 @@ hb_in_ranges (T u, T lo1, T hi1, T lo2, T hi2, T lo3, T hi3) #define FLAG_RANGE(x,y) (ASSERT_STATIC_EXPR_ZERO ((x) < (y)) + FLAG(y+1) - FLAG(x)) -template static inline void -hb_stable_sort (T *array, unsigned int len, int(*compar)(const T *, const T *), T2 *array2) -{ - for (unsigned int i = 1; i < len; i++) - { - unsigned int j = i; - while (j && compar (&array[j - 1], &array[i]) > 0) - j--; - if (i == j) - continue; - /* Move item i to occupy place for item j, shift what's in between. */ - { - T t = array[i]; - memmove (&array[j + 1], &array[j], (i - j) * sizeof (T)); - array[j] = t; - } - if (array2) - { - T2 t = array2[i]; - memmove (&array2[j + 1], &array2[j], (i - j) * sizeof (T2)); - array2[j] = t; - } - } -} - -template static inline void -hb_stable_sort (T *array, unsigned int len, int(*compar)(const T *, const T *)) -{ - hb_stable_sort (array, len, compar, (int *) nullptr); -} - -static inline hb_bool_t -hb_codepoint_parse (const char *s, unsigned int len, int base, hb_codepoint_t *out) -{ - /* Pain because we don't know whether s is nul-terminated. */ - char buf[64]; - len = MIN (ARRAY_LENGTH (buf) - 1, len); - strncpy (buf, s, len); - buf[len] = '\0'; - - char *end; - errno = 0; - unsigned long v = strtoul (buf, &end, base); - if (errno) return false; - if (*end) return false; - *out = v; - return true; -} - /* Vectorization */ @@ -1311,5 +1262,7 @@ _hb_memalign(void **memptr, size_t alignment, size_t size) #endif +#include "hb-dsalgs.hh" + #endif /* HB_PRIVATE_HH */