[array] Add .copy()
This commit is contained in:
parent
afb013f350
commit
e8b45c1933
@ -176,6 +176,17 @@ struct hb_array_t : hb_iter_with_fallback_t<hb_array_t<Type>, Type&>
|
||||
void free ()
|
||||
{ ::free ((void *) arrayZ); arrayZ = nullptr; length = 0; }
|
||||
|
||||
template <typename hb_serialize_context_t>
|
||||
hb_array_t copy (hb_serialize_context_t *c) const
|
||||
{
|
||||
TRACE_SERIALIZE (this);
|
||||
auto* out = c->template start_embed (arrayZ);
|
||||
if (unlikely (!c->extend_size (out, get_size ()))) return_trace (hb_array_t ());
|
||||
for (unsigned i = 0; i < length; i++)
|
||||
out[i] = arrayZ[i]; /* TODO: add version that calls c->copy() */
|
||||
return_trace (hb_array_t (out, length));
|
||||
}
|
||||
|
||||
template <typename hb_sanitize_context_t>
|
||||
bool sanitize (hb_sanitize_context_t *c) const
|
||||
{ return c->check_array (arrayZ, length); }
|
||||
|
@ -436,9 +436,7 @@ struct UnsizedArrayOf
|
||||
{
|
||||
TRACE_SERIALIZE (this);
|
||||
auto *out = c->start_embed (this);
|
||||
if (unlikely (!out->serialize (c, count))) return_trace (nullptr);
|
||||
for (unsigned i = 0; i < count; i++)
|
||||
out->arrayZ[i] = arrayZ[i]; /* TODO: add version that calls c->copy() */
|
||||
if (unlikely (!as_array (count).copy (c))) return_trace (nullptr);
|
||||
return_trace (out);
|
||||
}
|
||||
|
||||
@ -618,9 +616,9 @@ struct ArrayOf
|
||||
TRACE_SERIALIZE (this);
|
||||
auto *out = c->start_embed (this);
|
||||
unsigned count = len;
|
||||
if (unlikely (!out->serialize (c, count))) return_trace (nullptr);
|
||||
for (unsigned i = 0; i < count; i++)
|
||||
out->arrayZ[i] = arrayZ[i]; /* TODO: add version that calls c->copy() */
|
||||
if (unlikely (!c->extend_min (out))) return_trace (nullptr);
|
||||
c->check_assign (out->len, len);
|
||||
if (unlikely (!as_array ().copy (c))) return_trace (nullptr);
|
||||
return_trace (out);
|
||||
}
|
||||
|
||||
|
@ -323,7 +323,7 @@ struct hb_serialize_context_t
|
||||
allocate_size<void> (alignment - l);
|
||||
}
|
||||
|
||||
template <typename Type>
|
||||
template <typename Type = void>
|
||||
Type *start_embed (const Type *obj HB_UNUSED = nullptr) const
|
||||
{ return reinterpret_cast<Type *> (this->head); }
|
||||
template <typename Type>
|
||||
|
Loading…
Reference in New Issue
Block a user