[gvar] Micro-optimize boundary-checking

This commit is contained in:
Behdad Esfahbod 2022-11-22 13:12:22 -07:00
parent ab8346fb6f
commit 27c4037e59
1 changed files with 6 additions and 5 deletions

View File

@ -339,14 +339,17 @@ struct GlyphVariationData
if (unlikely (p + 1 > end)) return false; if (unlikely (p + 1 > end)) return false;
unsigned control = *p++; unsigned control = *p++;
unsigned run_count = (control & DELTA_RUN_COUNT_MASK) + 1; unsigned run_count = (control & DELTA_RUN_COUNT_MASK) + 1;
if (unlikely (i + run_count > count)) return false;
unsigned j; unsigned j;
if (control & DELTAS_ARE_ZERO) if (control & DELTAS_ARE_ZERO)
for (j = 0; j < run_count && i < count; j++, i++) {
for (j = 0; j < run_count; j++, i++)
deltas.arrayZ[i] = 0; deltas.arrayZ[i] = 0;
}
else if (control & DELTAS_ARE_WORDS) else if (control & DELTAS_ARE_WORDS)
{ {
if (unlikely (p + run_count * HBUINT16::static_size > end)) return false; if (unlikely (p + run_count * HBUINT16::static_size > end)) return false;
for (j = 0; j < run_count && i < count; j++, i++) for (j = 0; j < run_count; j++, i++)
{ {
deltas.arrayZ[i] = * (const HBINT16 *) p; deltas.arrayZ[i] = * (const HBINT16 *) p;
p += HBUINT16::static_size; p += HBUINT16::static_size;
@ -355,13 +358,11 @@ struct GlyphVariationData
else else
{ {
if (unlikely (p + run_count > end)) return false; if (unlikely (p + run_count > end)) return false;
for (j = 0; j < run_count && i < count; j++, i++) for (j = 0; j < run_count; j++, i++)
{ {
deltas.arrayZ[i] = * (const HBINT8 *) p++; deltas.arrayZ[i] = * (const HBINT8 *) p++;
} }
} }
if (unlikely (j < run_count))
return false;
} }
return true; return true;
} }