Add hb_blob_ptr_t

Use in a couple of places.  Push to bots to see how many unhappy before
I convert the rest.
This commit is contained in:
Behdad Esfahbod 2018-11-10 23:52:15 -05:00
parent e44046ec49
commit 5d0078a48b
5 changed files with 39 additions and 23 deletions

View File

@ -80,4 +80,27 @@ struct hb_blob_t
DECLARE_NULL_INSTANCE (hb_blob_t);
/*
* hb_blob_ptr_t
*/
template <typename P>
struct hb_blob_ptr_t
{
typedef typename hb_remove_pointer<P>::value T;
inline hb_blob_ptr_t (hb_blob_t *b_ = nullptr) : b (b_) {}
inline hb_blob_t * operator = (hb_blob_t *b_) { return b = b_; }
inline const T * operator -> (void) const { return get (); }
inline const T & operator * (void) const { return *get (); }
template <typename C> inline operator const C * (void) const { return get (); }
inline operator const char * (void) const { return (const char *) get (); }
inline const T * get (void) const { return b->as<T> (); }
inline hb_blob_t * get_blob (void) const { return b.get_raw (); }
inline unsigned int get_length (void) const { return get_blob ()->length; }
hb_nonnull_ptr_t<hb_blob_t> b;
};
#endif /* HB_BLOB_HH */

View File

@ -412,11 +412,10 @@ struct GDEF
inline void fini (void)
{
hb_blob_destroy (this->blob);
hb_blob_destroy (this->table.get_blob ());
}
hb_blob_t *blob;
hb_nonnull_ptr_t<const GDEF> table;
hb_blob_ptr_t<GDEF> table;
};
inline unsigned int get_size (void) const

View File

@ -2752,8 +2752,7 @@ struct GSUBGPOS
{
inline void init (hb_face_t *face)
{
this->blob = hb_sanitize_context_t().reference_table<T> (face);
table = this->blob->template as<T> ();
this->table = hb_sanitize_context_t().reference_table<T> (face);
this->lookup_count = table->get_lookup_count ();
@ -2770,11 +2769,10 @@ struct GSUBGPOS
for (unsigned int i = 0; i < this->lookup_count; i++)
this->accels[i].fini ();
free (this->accels);
hb_blob_destroy (this->blob);
hb_blob_destroy (this->table.get_blob ());
}
hb_blob_t *blob;
hb_nonnull_ptr_t<const T> table;
hb_blob_ptr_t<T> table;
unsigned int lookup_count;
hb_ot_layout_lookup_accelerator_t *accels;
};

View File

@ -194,17 +194,15 @@ _hb_ot_blacklist_gdef (unsigned int gdef_len,
void
OT::GDEF::accelerator_t::init (hb_face_t *face)
{
this->blob = hb_sanitize_context_t().reference_table<GDEF> (face);
this->table = hb_sanitize_context_t().reference_table<GDEF> (face);
if (unlikely (_hb_ot_blacklist_gdef (this->blob->length,
face->table.GSUB->blob->length,
face->table.GPOS->blob->length)))
if (unlikely (_hb_ot_blacklist_gdef (this->table.get_length (),
face->table.GSUB->table.get_length (),
face->table.GPOS->table.get_length ())))
{
hb_blob_destroy (this->blob);
this->blob = hb_blob_get_empty ();
hb_blob_destroy (this->table.get_blob ());
this->table = hb_blob_get_empty ();
}
table = this->blob->as<GDEF> ();
}
static void

View File

@ -179,11 +179,10 @@ struct name
{
inline void init (hb_face_t *face)
{
this->blob = hb_sanitize_context_t().reference_table<name> (face);
this->table = this->blob->as<name> ();
assert (this->blob->length >= this->table->stringOffset);
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_len = this->blob->length - 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);
@ -221,7 +220,7 @@ struct name
inline void fini (void)
{
this->names.fini ();
hb_blob_destroy (this->blob);
hb_blob_destroy (this->table.get_blob ());
}
inline int get_index (hb_ot_name_id_t name_id,
@ -253,11 +252,10 @@ struct name
}
private:
hb_blob_t *blob;
const void *pool;
unsigned int pool_len;
public:
hb_nonnull_ptr_t<const name> table;
hb_blob_ptr_t<name> table;
hb_vector_t<hb_ot_name_entry_t> names;
};