diff --git a/src/OT/glyf/SimpleGlyph.hh b/src/OT/glyf/SimpleGlyph.hh index 2b4aa99d2..9927f5301 100644 --- a/src/OT/glyf/SimpleGlyph.hh +++ b/src/OT/glyf/SimpleGlyph.hh @@ -184,7 +184,7 @@ struct SimpleGlyph if (unlikely (!bytes.check_range (&endPtsOfContours[num_contours]))) return false; 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 (phantom_only) return true; @@ -272,9 +272,9 @@ struct SimpleGlyph unsigned num_points = all_points.length - 4; hb_vector_t flags, x_coords, y_coords; - if (unlikely (!flags.alloc (num_points))) return false; - if (unlikely (!x_coords.alloc (2*num_points))) return false; - if (unlikely (!y_coords.alloc (2*num_points))) return false; + if (unlikely (!flags.alloc (num_points, true))) return false; + if (unlikely (!x_coords.alloc (2*num_points, true))) return false; + if (unlikely (!y_coords.alloc (2*num_points, true))) return false; uint8_t lastflag = 255, repeat = 0; int prev_x = 0, prev_y = 0; diff --git a/src/OT/glyf/glyf.hh b/src/OT/glyf/glyf.hh index 58af9ead5..3b7670669 100644 --- a/src/OT/glyf/glyf.hh +++ b/src/OT/glyf/glyf.hh @@ -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; hb_vector_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; for (auto _ : *plan->user_axes_location) diff --git a/src/hb-ot-layout-gsubgpos.hh b/src/hb-ot-layout-gsubgpos.hh index da47d0aa8..c15cacac2 100644 --- a/src/hb-ot-layout-gsubgpos.hh +++ b/src/hb-ot-layout-gsubgpos.hh @@ -4020,7 +4020,7 @@ struct hb_ot_layout_lookup_accelerator_t void init (const TLookup &lookup) { subtables.init (); - subtables.alloc (lookup.get_subtable_count ()); + subtables.alloc (lookup.get_subtable_count (), true); hb_accelerate_subtables_context_t c_accelerate_subtables (subtables); lookup.dispatch (&c_accelerate_subtables); diff --git a/src/hb-repacker.hh b/src/hb-repacker.hh index 7a3143cec..397b3868d 100644 --- a/src/hb-repacker.hh +++ b/src/hb-repacker.hh @@ -115,7 +115,7 @@ bool _promote_extensions_if_needed (graph::gsubgpos_graph_context_t& ext_context if (!ext_context.lookups) return true; hb_vector_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 ()) { diff --git a/src/hb-serialize.hh b/src/hb-serialize.hh index d5573281f..0c2f64cc4 100644 --- a/src/hb-serialize.hh +++ b/src/hb-serialize.hh @@ -81,11 +81,11 @@ struct hb_serialize_context_t head = o.head; tail = o.tail; 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++) 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++) virtual_links.push (o.virtual_links[i]); } diff --git a/src/hb-vector.hh b/src/hb-vector.hh index 9b52f5ca9..bb7af2b82 100644 --- a/src/hb-vector.hh +++ b/src/hb-vector.hh @@ -337,7 +337,7 @@ struct hb_vector_t } /* 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 ())) return false; @@ -347,8 +347,8 @@ struct hb_vector_t /* Reallocate */ - unsigned int new_allocated = allocated; - while (size >= new_allocated) + unsigned int new_allocated = exact ? size : allocated; + while (size > new_allocated) new_allocated += (new_allocated >> 1) + 8; Type *new_array = nullptr;