mirror of
https://github.com/storytold/harfbuzz.git
synced 2026-11-22 07:21:06 +01:00
[tuplevalues] Speed up encoding
This commit is contained in:
1 parent
56e10f04f0
commit
ebdeb2e30e
2 files changed
+18
-24
No files matched your search
+16
-23
@@ -1499,8 +1499,8 @@ struct TupleValues
|
||||
VALUE_RUN_COUNT_MASK = 0x3F
|
||||
};
|
||||
|
||||
static unsigned compile (hb_array_t<const int> values, /* IN */
|
||||
hb_array_t<unsigned char> encoded_bytes /* OUT */)
|
||||
static unsigned compile_unsafe (hb_array_t<const int> values, /* IN */
|
||||
unsigned char *encoded_bytes /* OUT */)
|
||||
{
|
||||
unsigned num_values = values.length;
|
||||
unsigned encoded_len = 0;
|
||||
@@ -1509,24 +1509,23 @@ struct TupleValues
|
||||
{
|
||||
int val = values.arrayZ[i];
|
||||
if (val == 0)
|
||||
encoded_len += encode_value_run_as_zeroes (i, encoded_bytes.sub_array (encoded_len), values);
|
||||
encoded_len += encode_value_run_as_zeroes (i, encoded_bytes + encoded_len, values);
|
||||
else if ((int8_t) val == val)
|
||||
encoded_len += encode_value_run_as_bytes (i, encoded_bytes.sub_array (encoded_len), values);
|
||||
encoded_len += encode_value_run_as_bytes (i, encoded_bytes + encoded_len, values);
|
||||
else if ((int16_t) val == val)
|
||||
encoded_len += encode_value_run_as_words (i, encoded_bytes.sub_array (encoded_len), values);
|
||||
encoded_len += encode_value_run_as_words (i, encoded_bytes + encoded_len, values);
|
||||
else
|
||||
encoded_len += encode_value_run_as_longs (i, encoded_bytes.sub_array (encoded_len), values);
|
||||
encoded_len += encode_value_run_as_longs (i, encoded_bytes + encoded_len, values);
|
||||
}
|
||||
return encoded_len;
|
||||
}
|
||||
|
||||
static unsigned encode_value_run_as_zeroes (unsigned& i,
|
||||
hb_array_t<unsigned char> encoded_bytes,
|
||||
unsigned char *it,
|
||||
hb_array_t<const int> values)
|
||||
{
|
||||
unsigned num_values = values.length;
|
||||
unsigned run_length = 0;
|
||||
auto it = encoded_bytes.iter ();
|
||||
unsigned encoded_len = 0;
|
||||
while (i < num_values && values.arrayZ[i] == 0)
|
||||
{
|
||||
@@ -1550,7 +1549,7 @@ struct TupleValues
|
||||
}
|
||||
|
||||
static unsigned encode_value_run_as_bytes (unsigned &i,
|
||||
hb_array_t<unsigned char> encoded_bytes,
|
||||
unsigned char *it,
|
||||
hb_array_t<const int> values)
|
||||
{
|
||||
unsigned start = i;
|
||||
@@ -1571,7 +1570,6 @@ struct TupleValues
|
||||
unsigned run_length = i - start;
|
||||
|
||||
unsigned encoded_len = 0;
|
||||
auto it = encoded_bytes.iter ();
|
||||
|
||||
while (run_length >= 64)
|
||||
{
|
||||
@@ -1579,10 +1577,9 @@ struct TupleValues
|
||||
encoded_len++;
|
||||
|
||||
for (unsigned j = 0; j < 64; j++)
|
||||
{
|
||||
*it++ = static_cast<char> (values.arrayZ[start + j]);
|
||||
encoded_len++;
|
||||
}
|
||||
it[j] = static_cast<char> (values.arrayZ[start + j]);
|
||||
it += 64;
|
||||
encoded_len += 64;
|
||||
|
||||
start += 64;
|
||||
run_length -= 64;
|
||||
@@ -1593,18 +1590,16 @@ struct TupleValues
|
||||
*it++ = (VALUES_ARE_BYTES | (run_length - 1));
|
||||
encoded_len++;
|
||||
|
||||
while (start < i)
|
||||
{
|
||||
*it++ = static_cast<char> (values.arrayZ[start++]);
|
||||
encoded_len++;
|
||||
}
|
||||
for (unsigned j = 0; j < run_length; j++)
|
||||
it[j] = static_cast<char> (values.arrayZ[start + j]);
|
||||
encoded_len += run_length;
|
||||
}
|
||||
|
||||
return encoded_len;
|
||||
}
|
||||
|
||||
static unsigned encode_value_run_as_words (unsigned &i,
|
||||
hb_array_t<unsigned char> encoded_bytes,
|
||||
unsigned char *it,
|
||||
hb_array_t<const int> values)
|
||||
{
|
||||
unsigned start = i;
|
||||
@@ -1631,7 +1626,6 @@ struct TupleValues
|
||||
}
|
||||
|
||||
unsigned run_length = i - start;
|
||||
auto it = encoded_bytes.iter ();
|
||||
unsigned encoded_len = 0;
|
||||
while (run_length >= 64)
|
||||
{
|
||||
@@ -1668,7 +1662,7 @@ struct TupleValues
|
||||
}
|
||||
|
||||
static unsigned encode_value_run_as_longs (unsigned &i,
|
||||
hb_array_t<unsigned char> encoded_bytes,
|
||||
unsigned char *it,
|
||||
hb_array_t<const int> values)
|
||||
{
|
||||
unsigned start = i;
|
||||
@@ -1684,7 +1678,6 @@ struct TupleValues
|
||||
}
|
||||
|
||||
unsigned run_length = i - start;
|
||||
auto it = encoded_bytes.iter ();
|
||||
unsigned encoded_len = 0;
|
||||
while (run_length >= 64)
|
||||
{
|
||||
|
||||
@@ -581,7 +581,8 @@ struct tuple_delta_t
|
||||
static unsigned compile_deltas (hb_array_t<unsigned char> encoded_bytes,
|
||||
hb_array_t<const int> deltas)
|
||||
{
|
||||
return TupleValues::compile (deltas, encoded_bytes);
|
||||
assert (encoded_bytes.length >= 5 * deltas.length);
|
||||
return TupleValues::compile_unsafe (deltas, encoded_bytes);
|
||||
}
|
||||
|
||||
bool calc_inferred_deltas (const contour_point_vector_t& orig_points,
|
||||
|
||||
Reference in new issue
Block a user