[array] Remove custom hb_bytes_t implementation
This commit is contained in:
parent
3656f56d47
commit
dcfa4a8d71
|
@ -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 <typename T>
|
||||
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 <typename Type>
|
||||
struct hb_sorted_array_t;
|
||||
|
||||
|
@ -85,11 +52,11 @@ struct hb_array_t
|
|||
|
||||
explicit_operator bool (void) const { return len; }
|
||||
|
||||
template <typename T> operator T * (void) const { return arrayZ; }
|
||||
template <typename T> 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<Type> 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<Type> 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 <typename T>
|
||||
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<Type> qsort (int (*cmp)(const void*, const void*))
|
||||
hb_sorted_array_t<Type> qsort (int (*cmp_)(const void*, const void*))
|
||||
{
|
||||
::qsort (arrayZ, len, sizeof (Type), cmp);
|
||||
::qsort (arrayZ, len, item_size, cmp_);
|
||||
return hb_sorted_array_t<Type> (*this);
|
||||
}
|
||||
hb_sorted_array_t<Type> qsort (void)
|
||||
{
|
||||
::qsort (arrayZ, len, sizeof (Type), Type::cmp);
|
||||
::qsort (arrayZ, len, item_size, Type::cmp);
|
||||
return hb_sorted_array_t<Type> (*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<Type> &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<Type> *a = (hb_array_t<Type> *) pa;
|
||||
hb_array_t<Type> *b = (hb_array_t<Type> *) pb;
|
||||
return b->cmp (*a);
|
||||
}
|
||||
|
||||
template <typename hb_sanitize_context_t>
|
||||
bool sanitize (hb_sanitize_context_t *c) const
|
||||
{ return c->check_array (arrayZ, len); }
|
||||
|
@ -243,4 +219,7 @@ inline hb_sorted_array_t<T> hb_sorted_array (T *array, unsigned int len)
|
|||
{ return hb_sorted_array_t<T> (array, len); }
|
||||
|
||||
|
||||
typedef hb_array_t<const char> hb_bytes_t;
|
||||
|
||||
|
||||
#endif /* HB_ARRAY_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
|
||||
{
|
||||
|
|
|
@ -182,7 +182,7 @@ struct name
|
|||
{
|
||||
this->table = hb_sanitize_context_t().reference_table<name> (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<const NameRecord> all_names (this->table->nameRecordZ.arrayZ,
|
||||
this->table->count);
|
||||
|
@ -248,12 +248,12 @@ struct name
|
|||
{
|
||||
const hb_array_t<const NameRecord> all_names (table->nameRecordZ.arrayZ, table->count);
|
||||
const NameRecord &record = all_names[idx];
|
||||
const hb_array_t<const char> 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<name> table;
|
||||
|
|
|
@ -66,12 +66,12 @@ hb_ot_name_list_names (hb_face_t *face,
|
|||
|
||||
template <typename in_utf_t, typename out_utf_t>
|
||||
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<hb_utf16_be_t, utf_t> (&bytes, text_size, text);
|
||||
return hb_ot_name_convert_utf<hb_utf16_be_t, utf_t> (bytes, text_size, text);
|
||||
|
||||
if (width == 1) /* ASCII */
|
||||
return hb_ot_name_convert_utf<hb_ascii_t, utf_t> (&bytes, text_size, text);
|
||||
return hb_ot_name_convert_utf<hb_ascii_t, utf_t> (bytes, text_size, text);
|
||||
}
|
||||
|
||||
if (text_size)
|
||||
|
|
Loading…
Reference in New Issue