[serialize] Add copy_bytes() and copy_blob()
This commit is contained in:
parent
1c6b369324
commit
142ac5a6be
|
@ -502,6 +502,9 @@ struct hb_bytes_t
|
||||||
{
|
{
|
||||||
inline hb_bytes_t (void) : bytes (nullptr), len (0) {}
|
inline hb_bytes_t (void) : bytes (nullptr), len (0) {}
|
||||||
inline hb_bytes_t (const char *bytes_, unsigned int len_) : bytes (bytes_), len (len_) {}
|
inline hb_bytes_t (const char *bytes_, unsigned int len_) : bytes (bytes_), len (len_) {}
|
||||||
|
inline hb_bytes_t (const void *bytes_, unsigned int len_) : bytes ((const char *) bytes_), len (len_) {}
|
||||||
|
|
||||||
|
inline void free (void) { ::free ((void *) bytes); bytes = nullptr; len = 0; }
|
||||||
|
|
||||||
inline int cmp (const hb_bytes_t &a) const
|
inline int cmp (const hb_bytes_t &a) const
|
||||||
{
|
{
|
||||||
|
|
|
@ -402,7 +402,7 @@ struct hb_serialize_context_t
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Type>
|
template <typename Type>
|
||||||
inline Type *copy (void)
|
inline Type *copy (void) const
|
||||||
{
|
{
|
||||||
assert (!this->ran_out_of_room);
|
assert (!this->ran_out_of_room);
|
||||||
unsigned int len = this->head - this->start;
|
unsigned int len = this->head - this->start;
|
||||||
|
@ -411,6 +411,25 @@ struct hb_serialize_context_t
|
||||||
memcpy (p, this->start, len);
|
memcpy (p, this->start, len);
|
||||||
return reinterpret_cast<Type *> (p);
|
return reinterpret_cast<Type *> (p);
|
||||||
}
|
}
|
||||||
|
inline hb_bytes_t copy_bytes (void) const
|
||||||
|
{
|
||||||
|
assert (!this->ran_out_of_room);
|
||||||
|
unsigned int len = this->head - this->start;
|
||||||
|
void *p = malloc (len);
|
||||||
|
if (p)
|
||||||
|
memcpy (p, this->start, len);
|
||||||
|
else
|
||||||
|
return hb_bytes_t ();
|
||||||
|
return hb_bytes_t (p, len);
|
||||||
|
}
|
||||||
|
inline hb_blob_t *copy_blob (void) const
|
||||||
|
{
|
||||||
|
assert (!this->ran_out_of_room);
|
||||||
|
return hb_blob_create (this->start,
|
||||||
|
this->head - this->start,
|
||||||
|
HB_MEMORY_MODE_DUPLICATE,
|
||||||
|
nullptr, nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
template <typename Type>
|
template <typename Type>
|
||||||
inline Type *allocate_size (unsigned int size)
|
inline Type *allocate_size (unsigned int size)
|
||||||
|
|
Loading…
Reference in New Issue