[serialize] Simplify copy

This commit is contained in:
Behdad Esfahbod 2019-03-30 19:01:23 -07:00
parent 0b1fe7b716
commit 8512dc565d
1 changed files with 7 additions and 15 deletions

View File

@ -246,16 +246,6 @@ struct hb_serialize_context_t
Type *extend (Type &obj) { return extend_size (obj, obj.get_size ()); }
/* Output routines. */
template <typename Type>
Type *copy () const
{
assert (this->successful);
unsigned int len = this->head - this->start;
void *p = malloc (len);
if (p)
memcpy (p, this->start, len);
return reinterpret_cast<Type *> (p);
}
hb_bytes_t copy_bytes () const
{
assert (this->successful);
@ -267,13 +257,15 @@ struct hb_serialize_context_t
return hb_bytes_t ();
return hb_bytes_t ((char *) p, len);
}
template <typename Type>
Type *copy () const
{ return reinterpret_cast<Type *> ((char *) copy_bytes ().arrayZ); }
hb_blob_t *copy_blob () const
{
assert (this->successful);
return hb_blob_create (this->start,
this->head - this->start,
HB_MEMORY_MODE_DUPLICATE,
nullptr, nullptr);
hb_bytes_t b = copy_bytes ();
return hb_blob_create (b.arrayZ, b.length,
HB_MEMORY_MODE_WRITABLE,
(char *) b.arrayZ, free);
}
public: /* TODO Make private. */