mirror of
https://github.com/storytold/harfbuzz.git
synced 2026-11-23 16:01:07 +01:00
[instancer/varstore] Speed up encoding merging
Don't recalculate chars from all row data.
This commit is contained in:
1 parent
f0a1289a6a
commit
a4a5089201
2 files changed
+30
-14
No files matched your search
@@ -2371,17 +2371,33 @@ struct delta_row_encoding_t
|
||||
hb_vector_t<const hb_vector_t<int>*> items;
|
||||
|
||||
delta_row_encoding_t () = default;
|
||||
template <typename iter_t,
|
||||
hb_requires (hb_is_source_of (iter_t, const hb_vector_t<int> *))>
|
||||
delta_row_encoding_t (iter_t rows = hb_array_t<const hb_vector_t<int> *> ())
|
||||
delta_row_encoding_t (hb_vector_t<const hb_vector_t<int>*> &&rows, unsigned num_cols)
|
||||
{
|
||||
assert (rows);
|
||||
|
||||
for (auto row : rows)
|
||||
add_row (row);
|
||||
items = std::move (rows);
|
||||
|
||||
if (unlikely (!chars.resize (num_cols)))
|
||||
return;
|
||||
|
||||
calculate_chars ();
|
||||
}
|
||||
|
||||
void merge (const delta_row_encoding_t& other)
|
||||
{
|
||||
items.alloc (items.length + other.items.length);
|
||||
for (auto row : other.items)
|
||||
add_row (row);
|
||||
|
||||
// Merge chars
|
||||
assert (chars.length == other.chars.length);
|
||||
for (unsigned i = 0; i < chars.length; i++)
|
||||
chars.arrayZ[i] = hb_max (chars.arrayZ[i], other.chars.arrayZ[i]);
|
||||
chars_changed ();
|
||||
}
|
||||
|
||||
void chars_changed ()
|
||||
{
|
||||
auto _ = chars.get_width ();
|
||||
width = _.first;
|
||||
overhead = get_chars_overhead (_.second);
|
||||
@@ -2391,9 +2407,6 @@ struct delta_row_encoding_t
|
||||
{
|
||||
assert (items);
|
||||
|
||||
if (unlikely (!chars.resize (items[0]->length)))
|
||||
return;
|
||||
|
||||
bool long_words = false;
|
||||
|
||||
for (auto row : items)
|
||||
@@ -2425,6 +2438,8 @@ struct delta_row_encoding_t
|
||||
if (v == 1)
|
||||
v = 2;
|
||||
}
|
||||
|
||||
chars_changed ();
|
||||
}
|
||||
|
||||
bool is_empty () const
|
||||
|
||||
@@ -1858,7 +1858,7 @@ struct item_variations_t
|
||||
}
|
||||
|
||||
if (major_rows)
|
||||
encoding_objs.push (delta_row_encoding_t (major_rows));
|
||||
encoding_objs.push (delta_row_encoding_t (std::move (major_rows), num_cols));
|
||||
|
||||
start_row += num_rows;
|
||||
}
|
||||
@@ -1910,7 +1910,7 @@ struct item_variations_t
|
||||
removed_todo_idxes.add (i);
|
||||
removed_todo_idxes.add (j);
|
||||
|
||||
delta_row_encoding_t combined_encoding_obj (hb_concat (encoding.items, other_encoding.items));
|
||||
encoding.merge (other_encoding);
|
||||
|
||||
for (unsigned idx = 0; idx < encoding_objs.length; idx++)
|
||||
{
|
||||
@@ -1918,7 +1918,7 @@ struct item_variations_t
|
||||
|
||||
const delta_row_encoding_t& obj = encoding_objs.arrayZ[idx];
|
||||
// In the unlikely event that the same encoding exists already, combine it.
|
||||
if (obj.width == combined_encoding_obj.width && obj.chars == combined_encoding_obj.chars)
|
||||
if (obj.width == encoding.width && obj.chars == encoding.chars)
|
||||
{
|
||||
// This is straight port from fonttools algorithm. I added this branch there
|
||||
// because I thought it can happen. But looks like we never get in here in
|
||||
@@ -1927,18 +1927,19 @@ struct item_variations_t
|
||||
// this path.
|
||||
|
||||
for (const auto& row : obj.items)
|
||||
combined_encoding_obj.add_row (row);
|
||||
encoding.add_row (row);
|
||||
|
||||
removed_todo_idxes.add (idx);
|
||||
continue;
|
||||
}
|
||||
|
||||
int combined_gain = combined_encoding_obj.gain_from_merging (obj);
|
||||
int combined_gain = encoding.gain_from_merging (obj);
|
||||
if (combined_gain > 0)
|
||||
queue.insert (combined_gain_idx_tuple_t (combined_gain, idx, encoding_objs.length), 0);
|
||||
}
|
||||
|
||||
encoding_objs.push (std::move (combined_encoding_obj));
|
||||
auto moved_encoding = std::move (encoding);
|
||||
encoding_objs.push (moved_encoding);
|
||||
}
|
||||
|
||||
int num_final_encodings = (int) encoding_objs.length - (int) removed_todo_idxes.get_population ();
|
||||
|
||||
Reference in new issue
Block a user