[serialize] use for each as #resolve_links, format

This commit is contained in:
Ebrahim Byagowi 2019-09-24 12:06:28 +03:30 committed by GitHub
parent 512551f276
commit 22b6c6a5c7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 15 deletions

View File

@ -91,9 +91,7 @@ struct hb_serialize_context_t
void fini () void fini ()
{ {
++ hb_iter (packed) for (object_t *_ : ++hb_iter (packed)) _->fini ();
| hb_apply ([] (object_t *_) { _->fini (); })
;
packed.fini (); packed.fini ();
this->packed_map.fini (); this->packed_map.fini ();
@ -292,7 +290,6 @@ struct hb_serialize_context_t
assert (packed.length > 1); assert (packed.length > 1);
for (const object_t* parent : ++hb_iter (packed)) for (const object_t* parent : ++hb_iter (packed))
{
for (const object_t::link_t &link : parent->links) for (const object_t::link_t &link : parent->links)
{ {
const object_t* child = packed[link.objidx]; const object_t* child = packed[link.objidx];
@ -313,7 +310,6 @@ struct hb_serialize_context_t
} }
} }
} }
}
unsigned int length () const { return this->head - current->head; } unsigned int length () const { return this->head - current->head; }
@ -354,9 +350,7 @@ struct hb_serialize_context_t
template <typename Type> template <typename Type>
Type *allocate_min () Type *allocate_min ()
{ { return this->allocate_size<Type> (Type::min_size); }
return this->allocate_size<Type> (Type::min_size);
}
template <typename Type> template <typename Type>
Type *embed (const Type *obj) Type *embed (const Type *obj)
@ -428,14 +422,12 @@ struct hb_serialize_context_t
/* Copy both items from head side and tail side... */ /* Copy both items from head side and tail side... */
unsigned int len = (this->head - this->start) unsigned int len = (this->head - this->start)
+ (this->end - this->tail); + (this->end - this->tail);
char *p = (char *) malloc (len); char *p = (char *) malloc (len);
if (p) if (unlikely (!p)) return hb_bytes_t ();
{
memcpy (p, this->start, this->head - this->start); memcpy (p, this->start, this->head - this->start);
memcpy (p + (this->head - this->start), this->tail, this->end - this->tail); memcpy (p + (this->head - this->start), this->tail, this->end - this->tail);
}
else
return hb_bytes_t ();
return hb_bytes_t (p, len); return hb_bytes_t (p, len);
} }
template <typename Type> template <typename Type>