mirror of
https://github.com/harfbuzz/harfbuzz.git
synced 2025-04-15 01:18:13 +00:00
[SimpleGlyph] Avoid branches in read_points
Calculate total bytes in read_flags and bounds-check once. This slows things down apparently, so going to revert.
This commit is contained in:
parent
62f5ed461e
commit
ba062c713e
1 changed files with 17 additions and 4 deletions
|
@ -123,20 +123,32 @@ struct SimpleGlyph
|
|||
first_flag = (uint8_t) first_flag | FLAG_OVERLAP_SIMPLE;
|
||||
}
|
||||
|
||||
__attribute__((noinline))
|
||||
static bool read_flags (const HBUINT8 *&p /* IN/OUT */,
|
||||
hb_array_t<contour_point_t> points_ /* IN/OUT */,
|
||||
const HBUINT8 *end)
|
||||
const HBUINT8 *end,
|
||||
unsigned &x_points_len,
|
||||
unsigned &y_points_len)
|
||||
{
|
||||
unsigned count = points_.length;
|
||||
x_points_len = y_points_len = 0;
|
||||
for (unsigned int i = 0; i < count;)
|
||||
{
|
||||
if (unlikely (p + 1 > end)) return false;
|
||||
uint8_t flag = *p++;
|
||||
x_points_len += bool (flag & FLAG_X_SHORT);
|
||||
x_points_len += 2 * bool ((flag & (FLAG_X_SHORT | FLAG_X_SAME)) == 0);
|
||||
y_points_len += bool (flag & FLAG_Y_SHORT);
|
||||
y_points_len += 2 * bool ((flag & (FLAG_Y_SHORT | FLAG_Y_SAME)) == 0);
|
||||
points_.arrayZ[i++].flag = flag;
|
||||
if (flag & FLAG_REPEAT)
|
||||
{
|
||||
if (unlikely (p + 1 > end)) return false;
|
||||
unsigned int repeat_count = *p++;
|
||||
x_points_len += repeat_count * bool (flag & FLAG_X_SHORT);
|
||||
x_points_len += repeat_count * 2 * bool ((flag & (FLAG_X_SHORT | FLAG_X_SAME)) == 0);
|
||||
y_points_len += repeat_count * bool (flag & FLAG_Y_SHORT);
|
||||
y_points_len += repeat_count * 2 * bool ((flag & (FLAG_Y_SHORT | FLAG_Y_SAME)) == 0);
|
||||
unsigned stop = hb_min (i + repeat_count, count);
|
||||
for (; i < stop; i++)
|
||||
points_.arrayZ[i].flag = flag;
|
||||
|
@ -145,6 +157,7 @@ struct SimpleGlyph
|
|||
return true;
|
||||
}
|
||||
|
||||
__attribute__((noinline))
|
||||
static bool read_points (const HBUINT8 *&p /* IN/OUT */,
|
||||
hb_array_t<contour_point_t> points_ /* IN/OUT */,
|
||||
const HBUINT8 *end,
|
||||
|
@ -160,7 +173,6 @@ struct SimpleGlyph
|
|||
unsigned flag = points_.arrayZ[i].flag;
|
||||
if (flag & short_flag)
|
||||
{
|
||||
if (unlikely (p + 1 > end)) return false;
|
||||
if (flag & same_flag)
|
||||
v += *p++;
|
||||
else
|
||||
|
@ -170,7 +182,6 @@ struct SimpleGlyph
|
|||
{
|
||||
if (!(flag & same_flag))
|
||||
{
|
||||
if (unlikely (p + HBINT16::static_size > end)) return false;
|
||||
v += *(const HBINT16 *) p;
|
||||
p += HBINT16::static_size;
|
||||
}
|
||||
|
@ -209,7 +220,9 @@ struct SimpleGlyph
|
|||
if (unlikely (p >= end)) return false;
|
||||
|
||||
/* Read x & y coordinates */
|
||||
return read_flags (p, points_, end)
|
||||
unsigned x_points_len, y_points_len;
|
||||
return read_flags (p, points_, end, x_points_len, y_points_len)
|
||||
&& end - p >= (int) (x_points_len + y_points_len)
|
||||
&& read_points (p, points_, end, &contour_point_t::x,
|
||||
FLAG_X_SHORT, FLAG_X_SAME)
|
||||
&& read_points (p, points_, end, &contour_point_t::y,
|
||||
|
|
Loading…
Add table
Reference in a new issue