From a47070cd40cee51fe792cb838ff9f21e0ea482c6 Mon Sep 17 00:00:00 2001 From: Ebrahim Byagowi Date: Wed, 18 Apr 2018 12:09:37 +0430 Subject: [PATCH] Minor, annotate the added tables with likely/unlikely (#997) --- src/hb-aat-fmtx-table.hh | 2 +- src/hb-aat-gcid-table.hh | 2 +- src/hb-aat-layout-ankr-table.hh | 7 ++++--- src/hb-aat-layout-bsln-table.hh | 9 +++++---- src/hb-aat-layout-feat-table.hh | 10 +++++----- src/hb-aat-layout-kerx-table.hh | 12 ++++++------ src/hb-aat-layout-trak-table.hh | 21 +++++++++++++-------- src/hb-aat-ltag-table.hh | 2 +- src/hb-ot-color-colr-table.hh | 10 +++++----- src/hb-ot-color-cpal-table.hh | 18 ++++++++++-------- src/hb-ot-color-sbix-table.hh | 2 +- src/hb-ot-color-svg-table.hh | 6 +++--- 12 files changed, 55 insertions(+), 46 deletions(-) diff --git a/src/hb-aat-fmtx-table.hh b/src/hb-aat-fmtx-table.hh index a9185c378..aa82c88cf 100644 --- a/src/hb-aat-fmtx-table.hh +++ b/src/hb-aat-fmtx-table.hh @@ -44,7 +44,7 @@ struct fmtx 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 01c2c5c35..b48a27984 100644 --- a/src/hb-aat-gcid-table.hh +++ b/src/hb-aat-gcid-table.hh @@ -44,7 +44,7 @@ struct gcid 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 dc6582b60..3b7912b9d 100644 --- a/src/hb-aat-layout-ankr-table.hh +++ b/src/hb-aat-layout-ankr-table.hh @@ -58,9 +58,10 @@ struct ankr 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 a35b44838..df2bf5b43 100644 --- a/src/hb-aat-layout-bsln-table.hh +++ b/src/hb-aat-layout-bsln-table.hh @@ -42,7 +42,7 @@ struct BaselineTableFormat0Part 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 @@ struct BaselineTableFormat1Part 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 @@ struct BaselineTableFormat2Part 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 @@ struct bsln 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 e7329fe14..3e070d795 100644 --- a/src/hb-aat-layout-feat-table.hh +++ b/src/hb-aat-layout-feat-table.hh @@ -42,7 +42,7 @@ struct SettingName 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 @@ struct FeatureName 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 @@ struct feat 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 756faeff4..5004f27ff 100644 --- a/src/hb-aat-layout-kerx-table.hh +++ b/src/hb-aat-layout-kerx-table.hh @@ -147,7 +147,7 @@ struct KerxSubTableFormat2 { 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 @@ struct KerxSubTableFormat4 { 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 @@ struct KerxTable 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 @@ struct kerx 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 (*this); - if (!(table->sanitize (c))) + if (unlikely (!(table->sanitize (c)))) return_trace (false); for (unsigned int i = 0; i < nTables - 1; ++i) { table = &StructAfter (*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 70f551a88..d093c1c70 100644 --- a/src/hb-aat-layout-trak-table.hh +++ b/src/hb-aat-layout-trak-table.hh @@ -44,12 +44,17 @@ namespace AAT { 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 @@ struct TrackTableEntry 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 > - 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 @@ struct trak { 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 @@ struct trak 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 0796c671e..15c4e89cb 100644 --- a/src/hb-aat-ltag-table.hh +++ b/src/hb-aat-ltag-table.hh @@ -61,7 +61,7 @@ struct ltag 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 4d761fca0..ce6702d2a 100644 --- a/src/hb-ot-color-colr-table.hh +++ b/src/hb-ot-color-colr-table.hh @@ -61,7 +61,7 @@ struct BaseGlyphRecord 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 @@ struct COLR 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 @@ struct COLR 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 cb98f7d66..2c312748d 100644 --- a/src/hb-ot-color-cpal-table.hh +++ b/src/hb-ot-color-cpal-table.hh @@ -143,13 +143,14 @@ struct CPAL 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 @@ struct CPAL return_trace (true); const CPALV1Tail &v1 = StructAfter (*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 @@ struct CPAL 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 (*this); @@ -176,7 +177,7 @@ struct CPAL 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 (*this); @@ -191,11 +192,12 @@ struct CPAL 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& 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 7dea61402..09d0cc57a 100644 --- a/src/hb-ot-color-sbix-table.hh +++ b/src/hb-ot-color-sbix-table.hh @@ -89,7 +89,7 @@ struct sbix 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 1357b7883..47b3292b7 100644 --- a/src/hb-ot-color-svg-table.hh +++ b/src/hb-ot-color-svg-table.hh @@ -71,7 +71,7 @@ struct SVGDocumentIndex { TRACE_SANITIZE (this); return_trace (c->check_struct (this) && - entries.sanitize (c, this)); + entries.sanitize (c, this)); } protected: @@ -88,8 +88,8 @@ struct SVG 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