diff --git a/src/OT/Color/COLR/COLR.hh b/src/OT/Color/COLR/COLR.hh index 7d72a11a4..6f575934f 100644 --- a/src/OT/Color/COLR/COLR.hh +++ b/src/OT/Color/COLR/COLR.hh @@ -2060,7 +2060,7 @@ struct delta_set_index_map_subset_plan_t outer_bit_count = 1; inner_bit_count = 1; - if (unlikely (!output_map.resize (map_count, false))) return false; + if (unlikely (!output_map.resize_dirty (map_count))) return false; for (unsigned idx = 0; idx < map_count; idx++) { diff --git a/src/OT/glyf/SimpleGlyph.hh b/src/OT/glyf/SimpleGlyph.hh index c0f01405c..9f4a2bac5 100644 --- a/src/OT/glyf/SimpleGlyph.hh +++ b/src/OT/glyf/SimpleGlyph.hh @@ -189,7 +189,7 @@ struct SimpleGlyph unsigned old_length = points.length; points.alloc (points.length + num_points + 4); // Allocate for phantom points, to avoid a possible copy - if (unlikely (!points.resize (points.length + num_points, false))) return false; + if (unlikely (!points.resize_dirty (points.length + num_points))) return false; auto points_ = points.as_array ().sub_array (old_length); if (!phantom_only) hb_memset (points_.arrayZ, 0, sizeof (contour_point_t) * num_points); diff --git a/src/hb-bimap.hh b/src/hb-bimap.hh index f54147254..f9c0e8870 100644 --- a/src/hb-bimap.hh +++ b/src/hb-bimap.hh @@ -176,7 +176,7 @@ struct hb_inc_bimap_t { hb_codepoint_t count = get_population (); hb_vector_t work; - if (unlikely (!work.resize (count, false))) return; + if (unlikely (!work.resize_dirty (count))) return; for (hb_codepoint_t rhs = 0; rhs < count; rhs++) work.arrayZ[rhs] = back_map[rhs]; diff --git a/src/hb-bit-set.hh b/src/hb-bit-set.hh index 9134f7ba6..b89046746 100644 --- a/src/hb-bit-set.hh +++ b/src/hb-bit-set.hh @@ -91,10 +91,10 @@ struct hb_bit_set_t if (pages.length < count && (unsigned) pages.allocated < count && count <= 2) exact_size = true; // Most sets are small and local - if (unlikely (!pages.resize (count, clear, exact_size) || - !page_map.resize (count, clear))) + if (unlikely (!pages.resize_full (count, clear, exact_size) || + !page_map.resize_full (count, clear, false))) { - pages.resize (page_map.length, clear, exact_size); + pages.resize_full (page_map.length, clear, exact_size); successful = false; return false; } @@ -395,7 +395,7 @@ struct hb_bit_set_t { if (unlikely (!successful)) return; unsigned int count = other.pages.length; - if (unlikely (!resize (count, false, exact_size))) + if (unlikely (!resize (count, false, exact_size))) return; population = other.population; diff --git a/src/hb-kbts.cc b/src/hb-kbts.cc index eb3bfc225..0159256b5 100644 --- a/src/hb-kbts.cc +++ b/src/hb-kbts.cc @@ -168,7 +168,7 @@ _hb_kbts_shape (hb_shape_plan_t *shape_plan, } hb_vector_t kb_glyphs; - if (unlikely (!kb_glyphs.resize_exact (buffer->len, false))) + if (unlikely (!kb_glyphs.resize_full (buffer->len, false, true))) return false; for (size_t i = 0; i < buffer->len; ++i) @@ -223,7 +223,7 @@ _hb_kbts_shape (hb_shape_plan_t *shape_plan, * https://github.com/JimmyLefevre/kb/issues/32 */ glyph_capacity += glyph_capacity / 2; - if (unlikely (!kb_glyphs.resize_exact (glyph_capacity, false))) + if (unlikely (!kb_glyphs.resize_full (glyph_capacity, false, true))) return false; } diff --git a/src/hb-open-type.hh b/src/hb-open-type.hh index 707f34a1d..d8a1fa6ee 100644 --- a/src/hb-open-type.hh +++ b/src/hb-open-type.hh @@ -1742,7 +1742,7 @@ struct TupleValues unsigned run_count = (control & VALUE_RUN_COUNT_MASK) + 1; if (consume_all) { - if (unlikely (!values.resize (values.length + run_count, false))) + if (unlikely (!values.resize_dirty (values.length + run_count))) return false; } unsigned stop = i + run_count; diff --git a/src/hb-ot-cff1-table.hh b/src/hb-ot-cff1-table.hh index f6f9ed2c1..66c375b2c 100644 --- a/src/hb-ot-cff1-table.hh +++ b/src/hb-ot-cff1-table.hh @@ -326,7 +326,7 @@ struct Charset0 void collect_glyph_to_sid_map (glyph_to_sid_map_t *mapping, unsigned int num_glyphs) const { - mapping->resize (num_glyphs, false); + mapping->resize_dirty (num_glyphs); for (hb_codepoint_t gid = 1; gid < num_glyphs; gid++) mapping->arrayZ[gid] = {sids[gid - 1], gid}; } @@ -426,7 +426,7 @@ struct Charset1_2 { void collect_glyph_to_sid_map (glyph_to_sid_map_t *mapping, unsigned int num_glyphs) const { - mapping->resize (num_glyphs, false); + mapping->resize_dirty (num_glyphs); hb_codepoint_t gid = 1; if (gid >= num_glyphs) return; diff --git a/src/hb-ot-layout-gsubgpos.hh b/src/hb-ot-layout-gsubgpos.hh index 060218f5b..f88068ebe 100644 --- a/src/hb-ot-layout-gsubgpos.hh +++ b/src/hb-ot-layout-gsubgpos.hh @@ -1361,7 +1361,7 @@ static bool match_input (hb_ot_apply_context_t *c, } if (unlikely (i + 1 > c->match_positions.length && - !c->match_positions.resize (i + 1, false))) + !c->match_positions.resize_dirty (i + 1))) return_trace (false); c->match_positions.arrayZ[i] = skippy_iter.idx; @@ -1850,7 +1850,7 @@ static inline void apply_lookup (hb_ot_apply_context_t *c, if (unlikely (delta + count > HB_MAX_CONTEXT_LENGTH)) break; if (unlikely (count + delta > c->match_positions.length && - !c->match_positions.resize (count + delta, false))) + !c->match_positions.resize_dirty (count + delta))) return; } else diff --git a/src/hb-ot-var-common.hh b/src/hb-ot-var-common.hh index fc72ef152..791d279f2 100644 --- a/src/hb-ot-var-common.hh +++ b/src/hb-ot-var-common.hh @@ -466,7 +466,7 @@ struct tuple_delta_t unsigned cur_axis_count = axes_index_map.get_population (); /* allocate enough memory: 1 peak + 2 intermediate coords + fixed header size */ unsigned alloc_len = 3 * cur_axis_count * (F2DOT14::static_size) + 4; - if (unlikely (!compiled_tuple_header.resize (alloc_len, false))) return false; + if (unlikely (!compiled_tuple_header.resize_dirty (alloc_len))) return false; unsigned flag = 0; /* skip the first 4 header bytes: variationDataSize+tupleIndex */ @@ -536,7 +536,7 @@ struct tuple_delta_t hb_vector_t &compiled_deltas, /* OUT */ hb_vector_t &rounded_deltas /* scratch */) { - if (unlikely (!rounded_deltas.resize (point_indices.length, false))) + if (unlikely (!rounded_deltas.resize_dirty (point_indices.length))) return false; unsigned j = 0; @@ -553,7 +553,7 @@ struct tuple_delta_t if (y_deltas) alloc_len *= 2; - if (unlikely (!compiled_deltas.resize (alloc_len, false))) return false; + if (unlikely (!compiled_deltas.resize_dirty (alloc_len))) return false; unsigned encoded_len = compile_deltas (compiled_deltas, rounded_deltas); @@ -692,8 +692,8 @@ struct tuple_delta_t hb_vector_t &rounded_x_deltas = scratch.rounded_x_deltas; hb_vector_t &rounded_y_deltas = scratch.rounded_y_deltas; - if (unlikely (!rounded_x_deltas.resize (count, false) || - !rounded_y_deltas.resize (count, false))) + if (unlikely (!rounded_x_deltas.resize_dirty (count) || + !rounded_y_deltas.resize_dirty (count))) return false; for (unsigned i = 0; i < count; i++) @@ -774,7 +774,7 @@ struct tuple_delta_t /* allocate enough memories: 2 bytes for count + 3 bytes for each point */ unsigned num_bytes = 2 + 3 *num_points; - if (unlikely (!compiled_points.resize (num_bytes, false))) + if (unlikely (!compiled_points.resize_dirty (num_bytes))) return false; unsigned pos = 0; @@ -838,7 +838,7 @@ struct tuple_delta_t else compiled_points.arrayZ[header_pos] = (run_length - 1) | 0x80; } - return compiled_points.resize (pos, false); + return compiled_points.resize_dirty (pos); } static double infer_delta (double target_val, double prev_val, double next_val, double prev_delta, double next_delta) @@ -970,13 +970,13 @@ struct TupleVariationData bool apply_to_all = (indices.length == 0); unsigned num_deltas = apply_to_all ? point_count : indices.length; - if (unlikely (!deltas_x.resize (num_deltas, false) || + if (unlikely (!deltas_x.resize_dirty (num_deltas) || !TupleVariationData::decompile_deltas (p, deltas_x, end))) return false; if (is_gvar) { - if (unlikely (!deltas_y.resize (num_deltas, false) || + if (unlikely (!deltas_y.resize_dirty (num_deltas) || !TupleVariationData::decompile_deltas (p, deltas_y, end))) return false; } @@ -984,10 +984,10 @@ struct TupleVariationData tuple_delta_t var; var.axis_tuples = std::move (axis_tuples); if (unlikely (!var.indices.resize (point_count) || - !var.deltas_x.resize (point_count, false))) + !var.deltas_x.resize_dirty (point_count))) return false; - if (is_gvar && unlikely (!var.deltas_y.resize (point_count, false))) + if (is_gvar && unlikely (!var.deltas_y.resize_dirty (point_count))) return false; for (unsigned i = 0; i < num_deltas; i++) @@ -1029,8 +1029,8 @@ struct TupleVariationData /* In VarData, deltas are organized in rows, convert them into * column(region) based tuples, resize deltas_x first */ tuple_delta_t tuple; - if (!tuple.deltas_x.resize (item_count, false) || - !tuple.indices.resize (item_count, false)) + if (!tuple.deltas_x.resize_dirty (item_count) || + !tuple.indices.resize_dirty (item_count)) return false; for (unsigned i = 0; i < item_count; i++) @@ -1457,7 +1457,7 @@ struct TupleVariationData if (unlikely (p + 1 > end)) return false; count = ((count & POINT_RUN_COUNT_MASK) << 8) | *p++; } - if (unlikely (!points.resize (count, false))) return false; + if (unlikely (!points.resize_dirty (count))) return false; unsigned n = 0; unsigned i = 0; diff --git a/src/hb-ot-var-cvar-table.hh b/src/hb-ot-var-cvar-table.hh index c013f10e3..89e82a111 100644 --- a/src/hb-ot-var-cvar-table.hh +++ b/src/hb-ot-var-cvar-table.hh @@ -113,7 +113,7 @@ struct cvar bool apply_to_all = (indices.length == 0); unsigned num_deltas = apply_to_all ? num_cvt_item : indices.length; - if (unlikely (!unpacked_deltas.resize (num_deltas, false))) return false; + if (unlikely (!unpacked_deltas.resize_dirty (num_deltas))) return false; if (unlikely (!TupleVariationData<>::decompile_deltas (p, unpacked_deltas, end))) return false; for (unsigned int i = 0; i < num_deltas; i++) diff --git a/src/hb-ot-var-gvar-table.hh b/src/hb-ot-var-gvar-table.hh index 0562ba471..db201cceb 100644 --- a/src/hb-ot-var-gvar-table.hh +++ b/src/hb-ot-var-gvar-table.hh @@ -676,7 +676,7 @@ struct gvar_GVAR if (!deltas) { - if (unlikely (!deltas_vec.resize (count, false))) return false; + if (unlikely (!deltas_vec.resize_dirty (count))) return false; deltas = deltas_vec.as_array (); hb_memset (deltas.arrayZ + (phantom_only ? count - 4 : 0), 0, (phantom_only ? 4 : count) * sizeof (deltas[0])); @@ -693,9 +693,9 @@ struct gvar_GVAR bool apply_to_all = (indices.length == 0); unsigned num_deltas = apply_to_all ? points.length : indices.length; unsigned start_deltas = (phantom_only && num_deltas >= 4 ? num_deltas - 4 : 0); - if (unlikely (!x_deltas.resize (num_deltas, false))) return false; + if (unlikely (!x_deltas.resize_dirty (num_deltas))) return false; if (unlikely (!GlyphVariationData::decompile_deltas (p, x_deltas, end, false, start_deltas))) return false; - if (unlikely (!y_deltas.resize (num_deltas, false))) return false; + if (unlikely (!y_deltas.resize_dirty (num_deltas))) return false; if (unlikely (!GlyphVariationData::decompile_deltas (p, y_deltas, end, false, start_deltas))) return false; if (!apply_to_all) diff --git a/src/hb-subset-instancer-iup.cc b/src/hb-subset-instancer-iup.cc index 393cfedf8..a036fd355 100644 --- a/src/hb-subset-instancer-iup.cc +++ b/src/hb-subset-instancer-iup.cc @@ -136,7 +136,7 @@ static bool rotate_array (const hb_array_t& org_array, { unsigned n = org_array.length; if (!n) return true; - if (unlikely (!out.resize (n, false))) + if (unlikely (!out.resize_dirty (n))) return false; unsigned item_size = hb_static_size (T); @@ -184,8 +184,8 @@ static bool _iup_segment (const hb_array_t contour_points hb_vector_t& interp_y_deltas /* OUT */) { unsigned n = contour_points.length; - if (unlikely (!interp_x_deltas.resize (n, false) || - !interp_y_deltas.resize (n, false))) + if (unlikely (!interp_x_deltas.resize_dirty (n) || + !interp_y_deltas.resize_dirty (n))) return false; for (unsigned j = 0; j < 2; j++) @@ -289,8 +289,8 @@ static bool _iup_contour_optimize_dp (const contour_point_vector_t& contour_poin hb_vector_t &interp_y_deltas_scratch) { unsigned n = contour_points.length; - if (unlikely (!costs.resize (n, false) || - !chain.resize (n, false))) + if (unlikely (!costs.resize_dirty (n) || + !chain.resize_dirty (n))) return false; lookback = hb_min (lookback, MAX_LOOKBACK); @@ -445,9 +445,9 @@ static bool _iup_contour_optimize (const hb_array_t conto hb_vector_t repeat_x_deltas, repeat_y_deltas; contour_point_vector_t repeat_points; - if (unlikely (!repeat_x_deltas.resize (n * 2, false) || - !repeat_y_deltas.resize (n * 2, false) || - !repeat_points.resize (n * 2, false))) + if (unlikely (!repeat_x_deltas.resize_dirty (n * 2) || + !repeat_y_deltas.resize_dirty (n * 2) || + !repeat_points.resize_dirty (n * 2))) return false; unsigned contour_point_size = hb_static_size (contour_point_t); diff --git a/src/hb-subset-plan.cc b/src/hb-subset-plan.cc index c7d86cc76..9dba8bf13 100644 --- a/src/hb-subset-plan.cc +++ b/src/hb-subset-plan.cc @@ -719,10 +719,10 @@ hb_subset_plan_t::hb_subset_plan_t (hb_face_t *face, glyph_map->get(unicode_to_new_gid_list.arrayZ[i].second); } - bounds_width_vec.resize (_num_output_glyphs, false); + bounds_width_vec.resize_dirty (_num_output_glyphs); for (auto &v : bounds_width_vec) v = 0xFFFFFFFF; - bounds_height_vec.resize (_num_output_glyphs, false); + bounds_height_vec.resize_dirty (_num_output_glyphs); for (auto &v : bounds_height_vec) v = 0xFFFFFFFF; diff --git a/src/hb-vector.hh b/src/hb-vector.hh index 9a6b29b80..445e27f6d 100644 --- a/src/hb-vector.hh +++ b/src/hb-vector.hh @@ -549,7 +549,7 @@ struct hb_vector_t } HB_ALWAYS_INLINE_VECTOR_ALLOCS - bool resize (int size_, bool initialize = true, bool exact = false) + bool resize_full (int size_, bool initialize, bool exact) { unsigned int size = size_ < 0 ? 0u : (unsigned int) size_; if (!alloc (size, exact)) @@ -570,9 +570,19 @@ struct hb_vector_t return true; } HB_ALWAYS_INLINE_VECTOR_ALLOCS - bool resize_exact (int size_, bool initialize = true) + bool resize (int size_) { - return resize (size_, initialize, true); + return resize_full (size_, true, false); + } + HB_ALWAYS_INLINE_VECTOR_ALLOCS + bool resize_dirty (int size_) + { + return resize_full (size_, false, false); + } + HB_ALWAYS_INLINE_VECTOR_ALLOCS + bool resize_exact (int size_) + { + return resize_full (size_, true, true); } Type pop ()