[subset] Use vector.allocated size instead of tracking buf_size

This commit is contained in:
Behdad Esfahbod 2022-05-11 12:49:16 -06:00
parent f08537963b
commit 2e7f1ae48f
2 changed files with 6 additions and 7 deletions

View File

@ -123,7 +123,6 @@ static
bool bool
_try_subset (const TableType *table, _try_subset (const TableType *table,
hb_vector_t<char>* buf, hb_vector_t<char>* buf,
unsigned buf_size,
hb_subset_context_t* c /* OUT */) hb_subset_context_t* c /* OUT */)
{ {
c->serializer->start_serialize<TableType> (); c->serializer->start_serialize<TableType> ();
@ -136,6 +135,7 @@ _try_subset (const TableType *table,
return needed; return needed;
} }
unsigned buf_size = buf->allocated;
buf_size = buf_size * 2 + 16; buf_size = buf_size * 2 + 16;
DEBUG_MSG (SUBSET, nullptr, "OT::%c%c%c%c ran out of room; reallocating to %u bytes.", DEBUG_MSG (SUBSET, nullptr, "OT::%c%c%c%c ran out of room; reallocating to %u bytes.",
HB_UNTAG (c->table_tag), buf_size); HB_UNTAG (c->table_tag), buf_size);
@ -147,8 +147,8 @@ _try_subset (const TableType *table,
return needed; return needed;
} }
c->serializer->reset (buf->arrayZ, buf_size); c->serializer->reset (buf->arrayZ, buf->allocated);
return _try_subset (table, buf, buf_size, c); return _try_subset (table, buf, c);
} }
template<typename TableType> template<typename TableType>
@ -180,10 +180,10 @@ _subset (hb_subset_plan_t *plan, hb_vector_t<char> &buf)
} }
bool needed = false; bool needed = false;
hb_serialize_context_t serializer (buf.arrayZ, buf_size); hb_serialize_context_t serializer (buf.arrayZ, buf.allocated);
{ {
hb_subset_context_t c (source_blob, plan, &serializer, tag); hb_subset_context_t c (source_blob, plan, &serializer, tag);
needed = _try_subset (table, &buf, buf_size, &c); needed = _try_subset (table, &buf, &c);
} }
hb_blob_destroy (source_blob); hb_blob_destroy (source_blob);

View File

@ -70,9 +70,8 @@ struct hb_vector_t : std::conditional<sorted, hb_vector_t<Type, false>, hb_empty
} }
~hb_vector_t () { fini (); } ~hb_vector_t () { fini (); }
private:
int allocated = 0; /* == -1 means allocation failed. */
public: public:
int allocated = 0; /* == -1 means allocation failed. */
unsigned int length = 0; unsigned int length = 0;
public: public:
Type *arrayZ = nullptr; Type *arrayZ = nullptr;