Minor, annotate the added tables with likely/unlikely (#997)

This commit is contained in:
Ebrahim Byagowi 2018-04-18 12:09:37 +04:30 committed by GitHub
parent 1a309dcd72
commit a47070cd40
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 55 additions and 46 deletions

View File

@ -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). */

View File

@ -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:

View File

@ -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:

View File

@ -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) {

View File

@ -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:

View File

@ -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<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);
}

View File

@ -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<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 @@ 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;

View File

@ -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:

View File

@ -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;

View File

@ -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<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 @@ 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<CPALV1Tail> (*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<CPALV1Tail> (*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<BGRAColor>& color_records = this+colorRecordsZ;
return color_records[colorRecordIndicesZ[palette] + color_index];
}
protected:

View File

@ -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

View File

@ -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