From: Behdad Esfahbod Date: Mon, 17 Dec 2018 01:40:07 +0000 (-0500) Subject: [array] Remove custom hb_bytes_t implementation X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=dcfa4a8d711716de88b94a370663e9564e3e7ccc;p=platform%2Fupstream%2FlibHarfBuzzSharp.git [array] Remove custom hb_bytes_t implementation --- diff --git a/src/hb-array.hh b/src/hb-array.hh index 2fc50ed..0e99b07 100644 --- a/src/hb-array.hh +++ b/src/hb-array.hh @@ -30,39 +30,6 @@ #include "hb.hh" -struct hb_bytes_t -{ - hb_bytes_t (void) : arrayZ (nullptr), len (0) {} - hb_bytes_t (const char *bytes_, unsigned int len_) : arrayZ (bytes_), len (len_) {} - hb_bytes_t (const void *bytes_, unsigned int len_) : arrayZ ((const char *) bytes_), len (len_) {} - template - hb_bytes_t (const T& array) : arrayZ ((const char *) array.arrayZ), len (array.len * sizeof (array.arrayZ[0])) {} - - operator const void * (void) const { return arrayZ; } - operator const char * (void) const { return arrayZ; } - - explicit_operator bool (void) const { return len; } - - void free (void) { ::free ((void *) arrayZ); arrayZ = nullptr; len = 0; } - - int cmp (const hb_bytes_t &a) const - { - if (len != a.len) - return (int) a.len - (int) len; - return hb_memcmp (a.arrayZ, arrayZ, len); - } - static int cmp (const void *pa, const void *pb) - { - hb_bytes_t *a = (hb_bytes_t *) pa; - hb_bytes_t *b = (hb_bytes_t *) pb; - return b->cmp (*a); - } - - const char *arrayZ; - unsigned int len; -}; - - template struct hb_sorted_array_t; @@ -85,11 +52,11 @@ struct hb_array_t explicit_operator bool (void) const { return len; } - template operator T * (void) const { return arrayZ; } + template operator T * (void) const { return arrayZ; } Type * operator & (void) const { return arrayZ; } - unsigned int get_size (void) const { return len * sizeof (Type); } + unsigned int get_size (void) const { return len * item_size; } hb_array_t sub_array (unsigned int start_offset = 0, unsigned int *seg_count = nullptr /* IN/OUT */) const { @@ -108,12 +75,8 @@ struct hb_array_t hb_array_t sub_array (unsigned int start_offset, unsigned int seg_count) const { return sub_array (start_offset, &seg_count); } - hb_bytes_t as_bytes (void) const - { return hb_bytes_t (arrayZ, len * sizeof (Type)); } - template - Type *lsearch (const T &x, - Type *not_found = nullptr) + Type *lsearch (const T &x, Type *not_found = nullptr) { unsigned int count = len; for (unsigned int i = 0; i < count; i++) @@ -131,26 +94,39 @@ struct hb_array_t return not_found; } - hb_sorted_array_t qsort (int (*cmp)(const void*, const void*)) + hb_sorted_array_t qsort (int (*cmp_)(const void*, const void*)) { - ::qsort (arrayZ, len, sizeof (Type), cmp); + ::qsort (arrayZ, len, item_size, cmp_); return hb_sorted_array_t (*this); } hb_sorted_array_t qsort (void) { - ::qsort (arrayZ, len, sizeof (Type), Type::cmp); + ::qsort (arrayZ, len, item_size, Type::cmp); return hb_sorted_array_t (*this); } void qsort (unsigned int start, unsigned int end) { end = MIN (end, len); assert (start <= end); - ::qsort (arrayZ + start, end - start, sizeof (Type), Type::cmp); + ::qsort (arrayZ + start, end - start, item_size, Type::cmp); } void free (void) { ::free ((void *) arrayZ); arrayZ = nullptr; len = 0; } + int cmp (const hb_array_t &a) const + { + if (len != a.len) + return (int) a.len - (int) len; + return hb_memcmp (a.arrayZ, arrayZ, get_size ()); + } + static int cmp (const void *pa, const void *pb) + { + hb_array_t *a = (hb_array_t *) pa; + hb_array_t *b = (hb_array_t *) pb; + return b->cmp (*a); + } + template bool sanitize (hb_sanitize_context_t *c) const { return c->check_array (arrayZ, len); } @@ -243,4 +219,7 @@ inline hb_sorted_array_t hb_sorted_array (T *array, unsigned int len) { return hb_sorted_array_t (array, len); } +typedef hb_array_t hb_bytes_t; + + #endif /* HB_ARRAY_HH */ diff --git a/src/hb-machinery.hh b/src/hb-machinery.hh index e3ca055..41012dd 100644 --- a/src/hb-machinery.hh +++ b/src/hb-machinery.hh @@ -619,7 +619,7 @@ struct hb_serialize_context_t memcpy (p, this->start, len); else return hb_bytes_t (); - return hb_bytes_t (p, len); + return hb_bytes_t ((char *) p, len); } hb_blob_t *copy_blob (void) const { diff --git a/src/hb-ot-name-table.hh b/src/hb-ot-name-table.hh index 41baef4..ed51d78 100644 --- a/src/hb-ot-name-table.hh +++ b/src/hb-ot-name-table.hh @@ -182,7 +182,7 @@ struct name { this->table = hb_sanitize_context_t().reference_table (face); assert (this->table.get_length () >= this->table->stringOffset); - this->pool = (this->table+this->table->stringOffset).arrayZ; + this->pool = (const char *) (const void *) (this->table+this->table->stringOffset); this->pool_len = this->table.get_length () - this->table->stringOffset; const hb_array_t all_names (this->table->nameRecordZ.arrayZ, this->table->count); @@ -248,12 +248,12 @@ struct name { const hb_array_t all_names (table->nameRecordZ.arrayZ, table->count); const NameRecord &record = all_names[idx]; - const hb_array_t string_pool ((const char *) pool, pool_len); - return string_pool.sub_array (record.offset, record.length).as_bytes (); + const hb_bytes_t string_pool (pool, pool_len); + return string_pool.sub_array (record.offset, record.length); } private: - const void *pool; + const char *pool; unsigned int pool_len; public: hb_blob_ptr_t table; diff --git a/src/hb-ot-name.cc b/src/hb-ot-name.cc index 4c88660..b2eda29 100644 --- a/src/hb-ot-name.cc +++ b/src/hb-ot-name.cc @@ -66,12 +66,12 @@ hb_ot_name_list_names (hb_face_t *face, template static inline unsigned int -hb_ot_name_convert_utf (const hb_bytes_t *bytes, +hb_ot_name_convert_utf (hb_bytes_t bytes, unsigned int *text_size /* IN/OUT */, typename out_utf_t::codepoint_t *text /* OUT */) { - unsigned int src_len = bytes->len / sizeof (typename in_utf_t::codepoint_t); - const typename in_utf_t::codepoint_t *src = (const typename in_utf_t::codepoint_t *) bytes->arrayZ; + unsigned int src_len = bytes.len / sizeof (typename in_utf_t::codepoint_t); + const typename in_utf_t::codepoint_t *src = (const typename in_utf_t::codepoint_t *) bytes.arrayZ; const typename in_utf_t::codepoint_t *src_end = src + src_len; typename out_utf_t::codepoint_t *dst = text; @@ -129,10 +129,10 @@ hb_ot_name_get_utf (hb_face_t *face, hb_bytes_t bytes = name.get_name (idx); if (width == 2) /* UTF16-BE */ - return hb_ot_name_convert_utf (&bytes, text_size, text); + return hb_ot_name_convert_utf (bytes, text_size, text); if (width == 1) /* ASCII */ - return hb_ot_name_convert_utf (&bytes, text_size, text); + return hb_ot_name_convert_utf (bytes, text_size, text); } if (text_size)