Minor, annotate the added tables with likely/unlikely (#997)
diff --git a/src/hb-aat-fmtx-table.hh b/src/hb-aat-fmtx-table.hh index a9185c3..aa82c88 100644 --- a/src/hb-aat-fmtx-table.hh +++ b/src/hb-aat-fmtx-table.hh
@@ -44,7 +44,7 @@ inline bool sanitize (hb_sanitize_context_t *c) const { TRACE_SANITIZE (this); - return_trace (c->check_struct (this)); + return_trace (likely (c->check_struct (this))); } FixedVersion<>version; /* Version (set to 0x00020000). */
diff --git a/src/hb-aat-gcid-table.hh b/src/hb-aat-gcid-table.hh index 01c2c5c..b48a279 100644 --- a/src/hb-aat-gcid-table.hh +++ b/src/hb-aat-gcid-table.hh
@@ -44,7 +44,7 @@ inline bool sanitize (hb_sanitize_context_t *c) const { TRACE_SANITIZE (this); - return_trace (c->check_struct (this) && CIDs.sanitize (c)); + return_trace (likely (c->check_struct (this) && CIDs.sanitize (c))); } protected:
diff --git a/src/hb-aat-layout-ankr-table.hh b/src/hb-aat-layout-ankr-table.hh index dc6582b..3b7912b 100644 --- a/src/hb-aat-layout-ankr-table.hh +++ b/src/hb-aat-layout-ankr-table.hh
@@ -58,9 +58,10 @@ inline bool sanitize (hb_sanitize_context_t *c) const { TRACE_SANITIZE (this); - return_trace (c->check_struct (this) && version == 0 && - lookupTable.sanitize (c, this) && - anchors.sanitize (c, this)); + return_trace (likely (c->check_struct (this) && + version == 0 && + lookupTable.sanitize (c, this) && + anchors.sanitize (c, this))); } protected:
diff --git a/src/hb-aat-layout-bsln-table.hh b/src/hb-aat-layout-bsln-table.hh index a35b448..df2bf5b 100644 --- a/src/hb-aat-layout-bsln-table.hh +++ b/src/hb-aat-layout-bsln-table.hh
@@ -42,7 +42,7 @@ inline bool sanitize (hb_sanitize_context_t *c) const { TRACE_SANITIZE (this); - return_trace (c->check_struct (this)); + return_trace (likely (c->check_struct (this))); } protected: @@ -60,7 +60,8 @@ inline bool sanitize (hb_sanitize_context_t *c) const { TRACE_SANITIZE (this); - return_trace (c->check_struct (this) && lookupTable.sanitize (c)); + return_trace (likely (c->check_struct (this) && + lookupTable.sanitize (c))); } protected: @@ -77,7 +78,7 @@ inline bool sanitize (hb_sanitize_context_t *c) const { TRACE_SANITIZE (this); - return_trace (c->check_struct (this)); + return_trace (likely (c->check_struct (this))); } protected: @@ -120,7 +121,7 @@ inline bool sanitize (hb_sanitize_context_t *c) const { TRACE_SANITIZE (this); - if (!(c->check_struct (this) && defaultBaseline < 32)) + if (unlikely (!(c->check_struct (this) && defaultBaseline < 32))) return_trace (false); switch (format) {
diff --git a/src/hb-aat-layout-feat-table.hh b/src/hb-aat-layout-feat-table.hh index e7329fe..3e070d7 100644 --- a/src/hb-aat-layout-feat-table.hh +++ b/src/hb-aat-layout-feat-table.hh
@@ -42,7 +42,7 @@ inline bool sanitize (hb_sanitize_context_t *c) const { TRACE_SANITIZE (this); - return_trace (c->check_struct (this)); + return_trace (likely (c->check_struct (this))); } protected: @@ -57,8 +57,8 @@ inline bool sanitize (hb_sanitize_context_t *c, const void *base) const { TRACE_SANITIZE (this); - return_trace (c->check_struct (this) && - (base+settingTable).sanitize (c, nSettings)); + return_trace (likely (c->check_struct (this) && + (base+settingTable).sanitize (c, nSettings))); } enum { @@ -98,8 +98,8 @@ inline bool sanitize (hb_sanitize_context_t *c) const { TRACE_SANITIZE (this); - return_trace (c->check_struct (this) && - names.sanitize (c, featureNameCount, this)); + return_trace (likely (c->check_struct (this) && + names.sanitize (c, featureNameCount, this))); } protected:
diff --git a/src/hb-aat-layout-kerx-table.hh b/src/hb-aat-layout-kerx-table.hh index 756faef..5004f27 100644 --- a/src/hb-aat-layout-kerx-table.hh +++ b/src/hb-aat-layout-kerx-table.hh
@@ -147,7 +147,7 @@ { TRACE_SANITIZE (this); return_trace (c->check_struct (this) && - rowWidth.sanitize (c) && + rowWidth.sanitize (c) && leftClassTable.sanitize (c, this) && rightClassTable.sanitize (c, this) && array.sanitize (c, this)); @@ -174,7 +174,7 @@ { TRACE_SANITIZE (this); return_trace (c->check_struct (this) && - rowWidth.sanitize (c) && + rowWidth.sanitize (c) && leftClassTable.sanitize (c, this) && rightClassTable.sanitize (c, this) && array.sanitize (c, this)); @@ -241,7 +241,7 @@ inline bool sanitize (hb_sanitize_context_t *c) const { TRACE_SANITIZE (this); - if (!c->check_struct (this)) + if (unlikely (!c->check_struct (this))) return_trace (false); switch (format) { @@ -301,18 +301,18 @@ inline bool sanitize (hb_sanitize_context_t *c) const { TRACE_SANITIZE (this); - if (!(c->check_struct (this))) + if (unlikely (!(c->check_struct (this)))) return_trace (false); /* TODO: Something like `morx`s ChainSubtable should be done here instead */ const KerxTable *table = &StructAfter<KerxTable> (*this); - if (!(table->sanitize (c))) + if (unlikely (!(table->sanitize (c)))) return_trace (false); for (unsigned int i = 0; i < nTables - 1; ++i) { table = &StructAfter<KerxTable> (*table); - if (!(table->sanitize (c))) + if (unlikely (!(table->sanitize (c)))) return_trace (false); }
diff --git a/src/hb-aat-layout-trak-table.hh b/src/hb-aat-layout-trak-table.hh index 70f551a..d093c1c 100644 --- a/src/hb-aat-layout-trak-table.hh +++ b/src/hb-aat-layout-trak-table.hh
@@ -44,12 +44,17 @@ struct TrackTableEntry { - inline bool sanitize (hb_sanitize_context_t *c, const void *base, unsigned int size) const + friend struct TrackData; + + inline bool sanitize (hb_sanitize_context_t *c, const void *base, + unsigned int size) const { TRACE_SANITIZE (this); - return_trace (c->check_struct (this) && (values.sanitize (c, base, size))); + return_trace (likely (c->check_struct (this) && + (valuesZ.sanitize (c, base, size)))); } + private: inline float get_track_value () const { return track.to_float (); @@ -57,14 +62,14 @@ inline int get_value (const void *base, unsigned int index) const { - return (base+values)[index]; + return (base+valuesZ)[index]; } protected: Fixed track; /* Track value for this record. */ NameID trackNameID; /* The 'name' table index for this track */ OffsetTo<UnsizedArrayOf<FWORD> > - values; /* Offset from start of tracking table to + valuesZ; /* Offset from start of tracking table to * per-size tracking values for this track. */ public: @@ -146,9 +151,9 @@ { TRACE_SANITIZE (this); - return_trace (c->check_struct (this) && - horizData.sanitize (c, this, this) && - vertData.sanitize (c, this, this)); + return_trace (unlikely (c->check_struct (this) && + horizData.sanitize (c, this, this) && + vertData.sanitize (c, this, this))); } inline bool apply (hb_aat_apply_context_t *c) const @@ -156,7 +161,7 @@ TRACE_APPLY (this); const float ptem = c->font->ptem; - if (ptem <= 0.f) + if (unlikely (ptem <= 0.f)) return_trace (false); hb_buffer_t *buffer = c->buffer;
diff --git a/src/hb-aat-ltag-table.hh b/src/hb-aat-ltag-table.hh index 0796c67..15c4e89 100644 --- a/src/hb-aat-ltag-table.hh +++ b/src/hb-aat-ltag-table.hh
@@ -61,7 +61,7 @@ inline bool sanitize (hb_sanitize_context_t *c) const { TRACE_SANITIZE (this); - return_trace (c->check_struct (this) && tagRanges.sanitize (c, this)); + return_trace (likely (c->check_struct (this) && tagRanges.sanitize (c, this))); } protected:
diff --git a/src/hb-ot-color-colr-table.hh b/src/hb-ot-color-colr-table.hh index 4d761fc..ce6702d 100644 --- a/src/hb-ot-color-colr-table.hh +++ b/src/hb-ot-color-colr-table.hh
@@ -61,7 +61,7 @@ inline bool sanitize (hb_sanitize_context_t *c) const { TRACE_SANITIZE (this); - return_trace (c->check_struct (this)); + return_trace (likely (c->check_struct (this))); } inline int cmp (hb_codepoint_t g) const { @@ -90,9 +90,9 @@ inline bool sanitize (hb_sanitize_context_t *c) const { TRACE_SANITIZE (this); - return_trace (c->check_struct (this) && - (this+baseGlyphsZ).sanitize (c, numBaseGlyphs) && - (this+layersZ).sanitize (c, numLayers)); + return_trace (likely (c->check_struct (this) && + (this+baseGlyphsZ).sanitize (c, numBaseGlyphs) && + (this+layersZ).sanitize (c, numLayers))); } inline bool get_base_glyph_record (hb_codepoint_t glyph_id, @@ -102,7 +102,7 @@ const BaseGlyphRecord* record; record = (BaseGlyphRecord *) bsearch (&glyph_id, &(this+baseGlyphsZ), numBaseGlyphs, sizeof (BaseGlyphRecord), compare_bgr); - if (!record) + if (unlikely (!record)) return false; *first_layer = record->firstLayerIdx;
diff --git a/src/hb-ot-color-cpal-table.hh b/src/hb-ot-color-cpal-table.hh index cb98f7d..2c31274 100644 --- a/src/hb-ot-color-cpal-table.hh +++ b/src/hb-ot-color-cpal-table.hh
@@ -143,13 +143,14 @@ inline bool sanitize (hb_sanitize_context_t *c) const { TRACE_SANITIZE (this); - if (!(c->check_struct (this) && // it checks colorRecordIndices also, see #get_size - (this+colorRecordsZ).sanitize (c, numColorRecords))) + if (unlikely (!(c->check_struct (this) && // it checks colorRecordIndices also + // see #get_size + (this+colorRecordsZ).sanitize (c, numColorRecords)))) return_trace (false); // Check for indices sanity so no need for doing it runtime for (unsigned int i = 0; i < numPalettes; ++i) - if (colorRecordIndicesZ[i] + numPaletteEntries > numColorRecords) + if (unlikely (colorRecordIndicesZ[i] + numPaletteEntries > numColorRecords)) return_trace (false); // If version is zero, we are done here; otherwise we need to check tail also @@ -157,7 +158,7 @@ return_trace (true); const CPALV1Tail &v1 = StructAfter<CPALV1Tail> (*this); - return_trace (v1.sanitize (c, this, numPalettes)); + return_trace (likely (v1.sanitize (c, this, numPalettes))); } inline unsigned int get_size (void) const @@ -167,7 +168,7 @@ inline hb_ot_color_palette_flags_t get_palette_flags (unsigned int palette) const { - if (version == 0 || palette >= numPalettes) + if (unlikely (version == 0 || palette >= numPalettes)) return HB_OT_COLOR_PALETTE_FLAG_DEFAULT; const CPALV1Tail& cpal1 = StructAfter<CPALV1Tail> (*this); @@ -176,7 +177,7 @@ inline unsigned int get_palette_name_id (unsigned int palette) const { - if (version == 0 || palette >= numPalettes) + if (unlikely (version == 0 || palette >= numPalettes)) return 0xFFFF; const CPALV1Tail& cpal1 = StructAfter<CPALV1Tail> (*this); @@ -191,11 +192,12 @@ inline hb_ot_color_t get_color_record_argb (unsigned int color_index, unsigned int palette) const { - if (color_index >= numPaletteEntries || palette >= numPalettes) + if (unlikely (color_index >= numPaletteEntries || palette >= numPalettes)) return 0; // No need for more range check as it is already done on #sanitize - return (this+colorRecordsZ)[colorRecordIndicesZ[palette] + color_index]; + const UnsizedArrayOf<BGRAColor>& color_records = this+colorRecordsZ; + return color_records[colorRecordIndicesZ[palette] + color_index]; } protected:
diff --git a/src/hb-ot-color-sbix-table.hh b/src/hb-ot-color-sbix-table.hh index 7dea614..09d0cc5 100644 --- a/src/hb-ot-color-sbix-table.hh +++ b/src/hb-ot-color-sbix-table.hh
@@ -89,7 +89,7 @@ inline bool sanitize (hb_sanitize_context_t *c) const { TRACE_SANITIZE (this); - return_trace (c->check_struct (this) && strikes.sanitize (c, this)); + return_trace (likely (c->check_struct (this) && strikes.sanitize (c, this))); } struct accelerator_t
diff --git a/src/hb-ot-color-svg-table.hh b/src/hb-ot-color-svg-table.hh index 1357b78..47b3292 100644 --- a/src/hb-ot-color-svg-table.hh +++ b/src/hb-ot-color-svg-table.hh
@@ -71,7 +71,7 @@ { TRACE_SANITIZE (this); return_trace (c->check_struct (this) && - entries.sanitize (c, this)); + entries.sanitize (c, this)); } protected: @@ -88,8 +88,8 @@ inline bool sanitize (hb_sanitize_context_t *c) const { TRACE_SANITIZE (this); - return_trace (c->check_struct (this) && - (this+svgDocIndex).sanitize (c)); + return_trace (likely (c->check_struct (this) && + (this+svgDocIndex).sanitize (c))); } struct accelerator_t