[vector] Add remove_unordered

Saves 5% in NotoNastaliq/1000 subset benchmark.
This commit is contained in:
Behdad Esfahbod 2022-11-26 14:48:57 -07:00
parent 4b8d8fbee4
commit 915c1a00cf
4 changed files with 18 additions and 5 deletions

View File

@ -132,7 +132,7 @@ struct graph_t
for (unsigned i = 0; i < parents.length; i++)
{
if (parents[i] != parent_index) continue;
parents.remove (i);
parents.remove_unordered (i);
break;
}
}
@ -148,7 +148,7 @@ struct graph_t
if ((obj.head + link.position) != offset)
continue;
obj.real_links.remove (i);
obj.real_links.remove_unordered (i);
return;
}
}

View File

@ -112,7 +112,7 @@ struct AnchorMatrix : public OT::Layout::GPOS_impl::AnchorMatrix
auto& child = c.graph.vertices_[child_idx];
child.remove_parent (this_index);
o.real_links.remove (i);
o.real_links.remove_unordered (i);
num_links--;
i--;
}

View File

@ -391,7 +391,7 @@ struct hb_vector_t
return v;
}
void remove (unsigned int i)
void remove_ordered (unsigned int i)
{
if (unlikely (i >= length))
return;
@ -400,6 +400,18 @@ struct hb_vector_t
length--;
}
template <bool Sorted = sorted,
hb_enable_if (!Sorted)>
void remove_unordered (unsigned int i)
{
if (unlikely (i >= length))
return;
if (i != length - 1)
arrayZ[i] = std::move (arrayZ[length - 1]);
arrayZ[length - 1].~Type ();
length--;
}
void shrink (int size_)
{
unsigned int size = size_ < 0 ? 0u : (unsigned int) size_;

View File

@ -162,7 +162,8 @@ main (int argc, char **argv)
v2 = v;
v2.remove (50);
v2.remove_ordered (50);
v2.remove_unordered (50);
}
{