mirror of
https://github.com/storytold/harfbuzz.git
synced 2026-11-21 06:51:01 +01:00
[instancer/varstore] Use heapify() instead of inserts()
This commit is contained in:
1 parent
12c4623757
commit
aba798ddab
2 files changed
+19
-3
No files matched your search
@@ -1894,7 +1894,8 @@ struct item_variations_t
|
||||
|
||||
/* main algorithm: repeatedly pick 2 best encodings to combine, and combine
|
||||
* them */
|
||||
hb_priority_queue_t<combined_gain_idx_tuple_t> queue;
|
||||
using item_t = hb_priority_queue_t<combined_gain_idx_tuple_t>::item_t;
|
||||
hb_vector_t<item_t> queue_items;
|
||||
unsigned num_todos = encoding_objs.length;
|
||||
for (unsigned i = 0; i < num_todos; i++)
|
||||
{
|
||||
@@ -1902,10 +1903,15 @@ struct item_variations_t
|
||||
{
|
||||
int combining_gain = encoding_objs.arrayZ[i].gain_from_merging (encoding_objs.arrayZ[j], scratch);
|
||||
if (combining_gain > 0)
|
||||
queue.insert (combined_gain_idx_tuple_t (-combining_gain, i, j), 0);
|
||||
{
|
||||
auto item = item_t (combined_gain_idx_tuple_t (-combining_gain, i, j), 0);
|
||||
queue_items.push (item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
hb_priority_queue_t<combined_gain_idx_tuple_t> queue (std::move (queue_items));
|
||||
|
||||
hb_bit_set_t removed_todo_idxes;
|
||||
while (queue)
|
||||
{
|
||||
|
||||
@@ -45,12 +45,22 @@
|
||||
template <typename K>
|
||||
struct hb_priority_queue_t
|
||||
{
|
||||
private:
|
||||
public:
|
||||
typedef hb_pair_t<K, unsigned> item_t;
|
||||
|
||||
private:
|
||||
hb_vector_t<item_t> heap;
|
||||
|
||||
public:
|
||||
|
||||
hb_priority_queue_t () = default;
|
||||
hb_priority_queue_t (hb_vector_t<item_t>&& other) : heap (std::move (other))
|
||||
{
|
||||
// Heapify the vector.
|
||||
for (int i = (heap.length / 2) - 1; i >= 0; i--)
|
||||
bubble_down (i);
|
||||
}
|
||||
|
||||
void reset () { heap.resize (0); }
|
||||
|
||||
bool in_error () const { return heap.in_error (); }
|
||||
|
||||
Reference in new issue
Block a user