mirror of
https://github.com/harfbuzz/harfbuzz.git
synced 2025-04-13 08:42:59 +00:00
[vector] Add faster extend() for array types
This commit is contained in:
parent
aaf5c06d62
commit
41626401b0
1 changed files with 29 additions and 16 deletions
|
@ -57,22 +57,6 @@ struct hb_vector_t
|
|||
{
|
||||
extend (o);
|
||||
}
|
||||
template <typename Iterable,
|
||||
hb_requires (hb_is_iterable (Iterable))>
|
||||
void extend (const Iterable &o)
|
||||
{
|
||||
auto iter = hb_iter (o);
|
||||
if (iter.is_random_access_iterator || iter.has_fast_len)
|
||||
alloc (hb_len (iter), true);
|
||||
while (iter)
|
||||
{
|
||||
if (unlikely (!alloc (length + 1)))
|
||||
return;
|
||||
unsigned room = allocated - length;
|
||||
for (unsigned i = 0; i < room && iter; i++)
|
||||
push_has_room (*iter++);
|
||||
}
|
||||
}
|
||||
hb_vector_t (const hb_vector_t &o) : hb_vector_t ()
|
||||
{
|
||||
alloc_exact (o.length);
|
||||
|
@ -100,6 +84,35 @@ struct hb_vector_t
|
|||
}
|
||||
~hb_vector_t () { fini (); }
|
||||
|
||||
template <typename Iterable,
|
||||
hb_requires (hb_is_iterable (Iterable))>
|
||||
void extend (const Iterable &o)
|
||||
{
|
||||
auto iter = hb_iter (o);
|
||||
if (iter.is_random_access_iterator || iter.has_fast_len)
|
||||
alloc (hb_len (iter), true);
|
||||
while (iter)
|
||||
{
|
||||
if (unlikely (!alloc (length + 1)))
|
||||
return;
|
||||
unsigned room = allocated - length;
|
||||
for (unsigned i = 0; i < room && iter; i++)
|
||||
push_has_room (*iter++);
|
||||
}
|
||||
}
|
||||
void extend (array_t o)
|
||||
{
|
||||
alloc (length + o.length);
|
||||
if (unlikely (in_error ())) return;
|
||||
copy_array (o);
|
||||
}
|
||||
void extend (c_array_t o)
|
||||
{
|
||||
alloc (length + o.length);
|
||||
if (unlikely (in_error ())) return;
|
||||
copy_array (o);
|
||||
}
|
||||
|
||||
public:
|
||||
int allocated = 0; /* < 0 means allocation failed. */
|
||||
unsigned int length = 0;
|
||||
|
|
Loading…
Add table
Reference in a new issue