mirror of
https://github.com/storytold/harfbuzz.git
synced 2026-11-20 14:31:10 +01:00
[priority-queue] Minor simplify
Tail-recursion definitely was being optimized by compiler, but I prefer writing it this way.
This commit is contained in:
1 parent
557653abce
commit
fc24ffbfb3
1 file changed
+11
-8
@@ -108,6 +108,7 @@ struct hb_priority_queue_t
|
||||
|
||||
void bubble_down (unsigned index)
|
||||
{
|
||||
repeat:
|
||||
assert (index < heap.length);
|
||||
|
||||
unsigned left = left_child (index);
|
||||
@@ -123,19 +124,20 @@ struct hb_priority_queue_t
|
||||
&& (!has_right || heap.arrayZ[index].first <= heap.arrayZ[right].first))
|
||||
return;
|
||||
|
||||
unsigned child;
|
||||
if (!has_right || heap.arrayZ[left].first < heap.arrayZ[right].first)
|
||||
{
|
||||
swap (index, left);
|
||||
bubble_down (left);
|
||||
return;
|
||||
}
|
||||
child = left;
|
||||
else
|
||||
child = right;
|
||||
|
||||
swap (index, right);
|
||||
bubble_down (right);
|
||||
swap (index, child);
|
||||
index = child;
|
||||
goto repeat;
|
||||
}
|
||||
|
||||
void bubble_up (unsigned index)
|
||||
{
|
||||
repeat:
|
||||
assert (index < heap.length);
|
||||
|
||||
if (index == 0) return;
|
||||
@@ -145,7 +147,8 @@ struct hb_priority_queue_t
|
||||
return;
|
||||
|
||||
swap (index, parent_index);
|
||||
bubble_up (parent_index);
|
||||
index = parent_index;
|
||||
goto repeat;
|
||||
}
|
||||
|
||||
void swap (unsigned a, unsigned b)
|
||||
|
||||
Reference in new issue
Block a user