[vector] Add internal API for exact-size allocation
Use it from a couple of places.
This commit is contained in:
parent
a0b46f3f6b
commit
2eacc37e08
|
@ -184,7 +184,7 @@ struct SimpleGlyph
|
||||||
if (unlikely (!bytes.check_range (&endPtsOfContours[num_contours]))) return false;
|
if (unlikely (!bytes.check_range (&endPtsOfContours[num_contours]))) return false;
|
||||||
unsigned int num_points = endPtsOfContours[num_contours - 1] + 1;
|
unsigned int num_points = endPtsOfContours[num_contours - 1] + 1;
|
||||||
|
|
||||||
points_.alloc (num_points + 4); // Allocate for phantom points, to avoid a possible copy
|
points_.alloc (num_points + 4, true); // Allocate for phantom points, to avoid a possible copy
|
||||||
if (!points_.resize (num_points)) return false;
|
if (!points_.resize (num_points)) return false;
|
||||||
if (phantom_only) return true;
|
if (phantom_only) return true;
|
||||||
|
|
||||||
|
@ -272,9 +272,9 @@ struct SimpleGlyph
|
||||||
unsigned num_points = all_points.length - 4;
|
unsigned num_points = all_points.length - 4;
|
||||||
|
|
||||||
hb_vector_t<uint8_t> flags, x_coords, y_coords;
|
hb_vector_t<uint8_t> flags, x_coords, y_coords;
|
||||||
if (unlikely (!flags.alloc (num_points))) return false;
|
if (unlikely (!flags.alloc (num_points, true))) return false;
|
||||||
if (unlikely (!x_coords.alloc (2*num_points))) return false;
|
if (unlikely (!x_coords.alloc (2*num_points, true))) return false;
|
||||||
if (unlikely (!y_coords.alloc (2*num_points))) return false;
|
if (unlikely (!y_coords.alloc (2*num_points, true))) return false;
|
||||||
|
|
||||||
uint8_t lastflag = 255, repeat = 0;
|
uint8_t lastflag = 255, repeat = 0;
|
||||||
int prev_x = 0, prev_y = 0;
|
int prev_x = 0, prev_y = 0;
|
||||||
|
|
|
@ -429,7 +429,7 @@ glyf::_create_font_for_instancing (const hb_subset_plan_t *plan) const
|
||||||
if (unlikely (font == hb_font_get_empty ())) return nullptr;
|
if (unlikely (font == hb_font_get_empty ())) return nullptr;
|
||||||
|
|
||||||
hb_vector_t<hb_variation_t> vars;
|
hb_vector_t<hb_variation_t> vars;
|
||||||
if (unlikely (!vars.alloc (plan->user_axes_location->get_population ())))
|
if (unlikely (!vars.alloc (plan->user_axes_location->get_population (), true)))
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
for (auto _ : *plan->user_axes_location)
|
for (auto _ : *plan->user_axes_location)
|
||||||
|
|
|
@ -4020,7 +4020,7 @@ struct hb_ot_layout_lookup_accelerator_t
|
||||||
void init (const TLookup &lookup)
|
void init (const TLookup &lookup)
|
||||||
{
|
{
|
||||||
subtables.init ();
|
subtables.init ();
|
||||||
subtables.alloc (lookup.get_subtable_count ());
|
subtables.alloc (lookup.get_subtable_count (), true);
|
||||||
hb_accelerate_subtables_context_t c_accelerate_subtables (subtables);
|
hb_accelerate_subtables_context_t c_accelerate_subtables (subtables);
|
||||||
lookup.dispatch (&c_accelerate_subtables);
|
lookup.dispatch (&c_accelerate_subtables);
|
||||||
|
|
||||||
|
|
|
@ -115,7 +115,7 @@ bool _promote_extensions_if_needed (graph::gsubgpos_graph_context_t& ext_context
|
||||||
if (!ext_context.lookups) return true;
|
if (!ext_context.lookups) return true;
|
||||||
|
|
||||||
hb_vector_t<lookup_size_t> lookup_sizes;
|
hb_vector_t<lookup_size_t> lookup_sizes;
|
||||||
lookup_sizes.alloc (ext_context.lookups.get_population ());
|
lookup_sizes.alloc (ext_context.lookups.get_population (), true);
|
||||||
|
|
||||||
for (unsigned lookup_index : ext_context.lookups.keys ())
|
for (unsigned lookup_index : ext_context.lookups.keys ())
|
||||||
{
|
{
|
||||||
|
|
|
@ -81,11 +81,11 @@ struct hb_serialize_context_t
|
||||||
head = o.head;
|
head = o.head;
|
||||||
tail = o.tail;
|
tail = o.tail;
|
||||||
next = nullptr;
|
next = nullptr;
|
||||||
real_links.alloc (o.num_real_links);
|
real_links.alloc (o.num_real_links, true);
|
||||||
for (unsigned i = 0 ; i < o.num_real_links; i++)
|
for (unsigned i = 0 ; i < o.num_real_links; i++)
|
||||||
real_links.push (o.real_links[i]);
|
real_links.push (o.real_links[i]);
|
||||||
|
|
||||||
virtual_links.alloc (o.num_virtual_links);
|
virtual_links.alloc (o.num_virtual_links, true);
|
||||||
for (unsigned i = 0; i < o.num_virtual_links; i++)
|
for (unsigned i = 0; i < o.num_virtual_links; i++)
|
||||||
virtual_links.push (o.virtual_links[i]);
|
virtual_links.push (o.virtual_links[i]);
|
||||||
}
|
}
|
||||||
|
|
|
@ -337,7 +337,7 @@ struct hb_vector_t
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Allocate for size but don't adjust length. */
|
/* Allocate for size but don't adjust length. */
|
||||||
bool alloc (unsigned int size)
|
bool alloc (unsigned int size, bool exact=false)
|
||||||
{
|
{
|
||||||
if (unlikely (in_error ()))
|
if (unlikely (in_error ()))
|
||||||
return false;
|
return false;
|
||||||
|
@ -347,8 +347,8 @@ struct hb_vector_t
|
||||||
|
|
||||||
/* Reallocate */
|
/* Reallocate */
|
||||||
|
|
||||||
unsigned int new_allocated = allocated;
|
unsigned int new_allocated = exact ? size : allocated;
|
||||||
while (size >= new_allocated)
|
while (size > new_allocated)
|
||||||
new_allocated += (new_allocated >> 1) + 8;
|
new_allocated += (new_allocated >> 1) + 8;
|
||||||
|
|
||||||
Type *new_array = nullptr;
|
Type *new_array = nullptr;
|
||||||
|
|
Loading…
Reference in New Issue