Remove most uses of direct comparison to Null objects

This commit is contained in:
Behdad Esfahbod 2018-08-06 06:30:12 -07:00
parent 3506672ce9
commit b912fbea17
12 changed files with 20 additions and 13 deletions

View File

@ -238,9 +238,9 @@ struct glyf
hb_blob_t *head_blob = hb_sanitize_context_t().reference_table<head> (face); hb_blob_t *head_blob = hb_sanitize_context_t().reference_table<head> (face);
const head *head_table = head_blob->as<head> (); const head *head_table = head_blob->as<head> ();
if (head_table == &Null(head) || (unsigned int) head_table->indexToLocFormat > 1 || head_table->glyphDataFormat != 0) if (head_table->indexToLocFormat > 1 || head_table->glyphDataFormat != 0)
{ {
/* head table is not present, or in an unknown format. Leave num_glyphs=0, that takes care of disabling us. */ /* Unknown format. Leave num_glyphs=0, that takes care of disabling us. */
hb_blob_destroy (head_blob); hb_blob_destroy (head_blob);
return; return;
} }
@ -270,7 +270,7 @@ struct glyf
inline bool get_composite (hb_codepoint_t glyph, inline bool get_composite (hb_codepoint_t glyph,
CompositeGlyphHeader::Iterator *composite /* OUT */) const CompositeGlyphHeader::Iterator *composite /* OUT */) const
{ {
if (this->glyf_table == &Null(glyf) || !num_glyphs) if (unlikely (!num_glyphs))
return false; return false;
unsigned int start_offset, end_offset; unsigned int start_offset, end_offset;

View File

@ -141,8 +141,8 @@ struct head
* -1: Only strongly right to left; * -1: Only strongly right to left;
* -2: Like -1 but also contains neutrals. */ * -2: Like -1 but also contains neutrals. */
public: public:
HBINT16 indexToLocFormat; /* 0 for short offsets, 1 for long. */ HBUINT16 indexToLocFormat; /* 0 for short offsets, 1 for long. */
HBINT16 glyphDataFormat; /* 0 for current format. */ HBUINT16 glyphDataFormat; /* 0 for current format. */
DEFINE_SIZE_STATIC (54); DEFINE_SIZE_STATIC (54);
}; };

View File

@ -349,6 +349,7 @@ struct GDEF
ComponentGlyph = 4 ComponentGlyph = 4
}; };
inline bool has_data (void) const { return version.to_int () != 0; }
inline bool has_glyph_classes (void) const { return glyphClassDef != 0; } inline bool has_glyph_classes (void) const { return glyphClassDef != 0; }
inline unsigned int get_glyph_class (hb_codepoint_t glyph) const inline unsigned int get_glyph_class (hb_codepoint_t glyph) const
{ return (this+glyphClassDef).get_class (glyph); } { return (this+glyphClassDef).get_class (glyph); }

View File

@ -2320,6 +2320,7 @@ struct Extension
struct GSUBGPOS struct GSUBGPOS
{ {
inline bool has_data (void) const { return version.to_int () != 0; }
inline unsigned int get_script_count (void) const inline unsigned int get_script_count (void) const
{ return (this+scriptList).len; } { return (this+scriptList).len; }
inline const Tag& get_script_tag (unsigned int i) const inline const Tag& get_script_tag (unsigned int i) const

View File

@ -904,7 +904,7 @@ hb_ot_layout_feature_with_variations_get_lookups (hb_face_t *face,
hb_bool_t hb_bool_t
hb_ot_layout_has_substitution (hb_face_t *face) hb_ot_layout_has_substitution (hb_face_t *face)
{ {
return &_get_gsub (face) != &Null(OT::GSUB); return _get_gsub (face).has_data ();
} }
/** /**
@ -1006,7 +1006,7 @@ hb_ot_layout_lookups_substitute_closure (hb_face_t *face,
hb_bool_t hb_bool_t
hb_ot_layout_has_positioning (hb_face_t *face) hb_ot_layout_has_positioning (hb_face_t *face)
{ {
return &_get_gpos (face) != &Null(OT::GPOS); return _get_gpos (face).has_data ();
} }
void void
@ -1341,5 +1341,5 @@ hb_ot_layout_substitute_lookup (OT::hb_ot_apply_context_t *c,
// hb_bool_t // hb_bool_t
// hb_ot_base_has_data (hb_face_t *face) // hb_ot_base_has_data (hb_face_t *face)
// { // {
// return &_get_base (face) != &Null(OT::BASE); // return _get_base (face).has_data ();
// } // }

View File

@ -686,6 +686,8 @@ struct MATH
{ {
static const hb_tag_t tableTag = HB_OT_TAG_MATH; static const hb_tag_t tableTag = HB_OT_TAG_MATH;
inline bool has_data (void) const { return version.to_int () != 0; }
inline bool sanitize (hb_sanitize_context_t *c) const inline bool sanitize (hb_sanitize_context_t *c) const
{ {
TRACE_SANITIZE (this); TRACE_SANITIZE (this);

View File

@ -55,7 +55,7 @@ _get_math (hb_face_t *face)
hb_bool_t hb_bool_t
hb_ot_math_has_data (hb_face_t *face) hb_ot_math_has_data (hb_face_t *face)
{ {
return &_get_math (face) != &Null(OT::MATH); return _get_math (face).has_data ();
} }
/** /**

View File

@ -313,6 +313,7 @@ arabic_fallback_plan_create (const hb_ot_shape_plan_t *plan,
if (arabic_fallback_plan_init_win1256 (fallback_plan, plan, font)) if (arabic_fallback_plan_init_win1256 (fallback_plan, plan, font))
return fallback_plan; return fallback_plan;
assert (fallback_plan->num_lookups == 0);
free (fallback_plan); free (fallback_plan);
return const_cast<arabic_fallback_plan_t *> (&Null(arabic_fallback_plan_t)); return const_cast<arabic_fallback_plan_t *> (&Null(arabic_fallback_plan_t));
} }
@ -320,7 +321,7 @@ arabic_fallback_plan_create (const hb_ot_shape_plan_t *plan,
static void static void
arabic_fallback_plan_destroy (arabic_fallback_plan_t *fallback_plan) arabic_fallback_plan_destroy (arabic_fallback_plan_t *fallback_plan)
{ {
if (!fallback_plan || fallback_plan == &Null(arabic_fallback_plan_t)) if (!fallback_plan || fallback_plan->num_lookups == 0)
return; return;
for (unsigned int i = 0; i < fallback_plan->num_lookups; i++) for (unsigned int i = 0; i < fallback_plan->num_lookups; i++)

View File

@ -87,6 +87,8 @@ struct fvar
{ {
static const hb_tag_t tableTag = HB_OT_TAG_fvar; static const hb_tag_t tableTag = HB_OT_TAG_fvar;
inline bool has_data (void) const { return version.to_int () != 0; }
inline bool sanitize (hb_sanitize_context_t *c) const inline bool sanitize (hb_sanitize_context_t *c) const
{ {
TRACE_SANITIZE (this); TRACE_SANITIZE (this);

View File

@ -65,7 +65,7 @@ _get_avar (hb_face_t *face)
hb_bool_t hb_bool_t
hb_ot_var_has_data (hb_face_t *face) hb_ot_var_has_data (hb_face_t *face)
{ {
return &_get_fvar (face) != &Null(OT::fvar); return _get_fvar (face).has_data ();
} }
/** /**

View File

@ -83,7 +83,7 @@ _subset (hb_subset_plan_t *plan)
hb_tag_t tag = TableType::tableTag; hb_tag_t tag = TableType::tableTag;
hb_bool_t result = false; hb_bool_t result = false;
if (table != &Null(TableType)) if (source_blob->data)
{ {
result = table->subset(plan); result = table->subset(plan);
} else { } else {

View File

@ -53,7 +53,7 @@ main (int argc, char **argv)
hb_blob_t *font_blob = hb_sanitize_context_t().sanitize_blob<OpenTypeFontFile> (blob); hb_blob_t *font_blob = hb_sanitize_context_t().sanitize_blob<OpenTypeFontFile> (blob);
const OpenTypeFontFile* sanitized = font_blob->as<OpenTypeFontFile> (); const OpenTypeFontFile* sanitized = font_blob->as<OpenTypeFontFile> ();
if (sanitized == &Null(OpenTypeFontFile)) if (!font_blob->data)
{ {
printf ("Sanitization of the file wasn't successful. Exit"); printf ("Sanitization of the file wasn't successful. Exit");
return 1; return 1;