diff --git a/src/OT/glyf/SimpleGlyph.hh b/src/OT/glyf/SimpleGlyph.hh index 1d42cc292..46eb47f68 100644 --- a/src/OT/glyf/SimpleGlyph.hh +++ b/src/OT/glyf/SimpleGlyph.hh @@ -190,7 +190,7 @@ struct SimpleGlyph unsigned int num_points = endPtsOfContours[num_contours - 1] + 1; unsigned old_length = points.length; - points.alloc (points.length + num_points + 4, true); // Allocate for phantom points, to avoid a possible copy + points.alloc_exact (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; auto points_ = points.as_array ().sub_array (old_length); if (!phantom_only) @@ -281,9 +281,9 @@ struct SimpleGlyph unsigned num_points = all_points.length - 4; hb_vector_t flags, x_coords, y_coords; - 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; + if (unlikely (!flags.alloc_exact (num_points))) return false; + if (unlikely (!x_coords.alloc_exact (2*num_points))) return false; + if (unlikely (!y_coords.alloc_exact (2*num_points))) return false; unsigned 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 d7cdc8f4c..d5db416db 100644 --- a/src/OT/glyf/glyf.hh +++ b/src/OT/glyf/glyf.hh @@ -94,7 +94,7 @@ struct glyf } hb_vector_t padded_offsets; - if (unlikely (!padded_offsets.alloc (c->plan->new_to_old_gid_list.length, true))) + if (unlikely (!padded_offsets.alloc_exact (c->plan->new_to_old_gid_list.length))) return_trace (false); hb_vector_t glyphs; @@ -493,7 +493,7 @@ glyf::_populate_subset_glyphs (const hb_subset_plan_t *plan, hb_vector_t& glyphs /* OUT */) const { OT::glyf_accelerator_t glyf (plan->source); - if (!glyphs.alloc (plan->new_to_old_gid_list.length, true)) return false; + if (!glyphs.alloc_exact (plan->new_to_old_gid_list.length)) return false; for (const auto &pair : plan->new_to_old_gid_list) { diff --git a/src/OT/name/name.hh b/src/OT/name/name.hh index e2a25d4a0..33de82d35 100644 --- a/src/OT/name/name.hh +++ b/src/OT/name/name.hh @@ -163,7 +163,7 @@ struct NameRecord if (platformID != 1) { unsigned text_size = hb_ot_name_convert_utf (*name_bytes, nullptr, nullptr); - + text_size++; // needs to consider NULL terminator for use in hb_ot_name_convert_utf() unsigned byte_len = text_size * hb_utf16_be_t::codepoint_t::static_size; name_str_utf16_be = (char *) hb_calloc (byte_len, 1); @@ -174,14 +174,14 @@ struct NameRecord } hb_ot_name_convert_utf (*name_bytes, &text_size, (hb_utf16_be_t::codepoint_t *) name_str_utf16_be); - + unsigned encoded_byte_len = text_size * hb_utf16_be_t::codepoint_t::static_size; if (!encoded_byte_len || !c->check_assign (out->length, encoded_byte_len, HB_SERIALIZE_ERROR_INT_OVERFLOW)) { c->revert (snap); hb_free (name_str_utf16_be); return_trace (nullptr); } - + encoded_bytes = hb_bytes_t (name_str_utf16_be, encoded_byte_len); } else @@ -392,7 +392,7 @@ struct name const hb_hashmap_t *name_table_overrides = &c->plan->name_table_overrides; #endif - + auto it = + nameRecordZ.as_array (count) | hb_filter (c->plan->name_ids, &NameRecord::nameID) @@ -485,7 +485,7 @@ struct name const hb_array_t all_names (this->table->nameRecordZ.arrayZ, this->table->count); - this->names.alloc (all_names.length, true); + this->names.alloc_exact (all_names.length); for (unsigned int i = 0; i < all_names.length; i++) { diff --git a/src/hb-aat-map.cc b/src/hb-aat-map.cc index a54640f0d..1a0dee022 100644 --- a/src/hb-aat-map.cc +++ b/src/hb-aat-map.cc @@ -88,7 +88,7 @@ hb_aat_map_builder_t::compile (hb_aat_map_t &m) /* Sort features by start/end events. */ hb_vector_t feature_events; - feature_events.alloc (features.length * 2 + 1, true); + feature_events.alloc_exact (features.length * 2 + 1); for (unsigned int i = 0; i < features.length; i++) { auto &feature = features.arrayZ[i]; diff --git a/src/hb-cff-interp-common.hh b/src/hb-cff-interp-common.hh index 6ca7500af..b0491385f 100644 --- a/src/hb-cff-interp-common.hh +++ b/src/hb-cff-interp-common.hh @@ -522,7 +522,7 @@ struct parsed_values_t void alloc (unsigned n) { - values.alloc (n, true); + values.alloc_exact (n); } void add_op (op_code_t op, const byte_str_ref_t& str_ref = byte_str_ref_t (), const VAL &v = VAL ()) diff --git a/src/hb-coretext-shape.cc b/src/hb-coretext-shape.cc index 7933a8748..e1496c4b1 100644 --- a/src/hb-coretext-shape.cc +++ b/src/hb-coretext-shape.cc @@ -528,7 +528,7 @@ hb_coretext_font_create (CTFontRef ct_font) hb_vector_t values; CFIndex count = CFDictionaryGetCount (variations); - if (unlikely (!vars.alloc (count) || !keys.resize (count) || !values.resize (count))) + if (unlikely (!vars.alloc_exact (count) || !keys.resize_exact (count) || !values.resize_exact (count))) goto done; // Fetch them one by one and collect in a vector of our own. diff --git a/src/hb-ot-var-gvar-table.hh b/src/hb-ot-var-gvar-table.hh index 96cc2e887..ff4fba3d2 100644 --- a/src/hb-ot-var-gvar-table.hh +++ b/src/hb-ot-var-gvar-table.hh @@ -72,7 +72,7 @@ struct glyph_variations_t const hb_subset_plan_t *plan, const hb_hashmap_t& new_gid_var_data_map) { - if (unlikely (!glyph_variations.alloc (plan->new_to_old_gid_list.length, true))) + if (unlikely (!glyph_variations.alloc_exact (plan->new_to_old_gid_list.length))) return false; auto it = hb_iter (plan->new_to_old_gid_list); diff --git a/src/hb-serialize.hh b/src/hb-serialize.hh index f066d0e31..63ab18586 100644 --- a/src/hb-serialize.hh +++ b/src/hb-serialize.hh @@ -78,11 +78,11 @@ struct hb_serialize_context_t head = o.head; tail = o.tail; next = nullptr; - real_links.alloc (o.num_real_links, true); + real_links.alloc_exact (o.num_real_links); for (unsigned i = 0 ; i < o.num_real_links; i++) real_links.push (o.real_links[i]); - virtual_links.alloc (o.num_virtual_links, true); + virtual_links.alloc_exact (o.num_virtual_links); for (unsigned i = 0; i < o.num_virtual_links; i++) virtual_links.push (o.virtual_links[i]); } @@ -172,7 +172,7 @@ struct hb_serialize_context_t auto all_links () const HB_AUTO_RETURN (( hb_concat (real_links, virtual_links) )); auto all_links_writer () HB_AUTO_RETURN - (( hb_concat (real_links.writer (), virtual_links.writer ()) )); + (( hb_concat (real_links.writer (), virtual_links.writer ()) )); }; struct snapshot_t diff --git a/src/hb-subset-cff-common.hh b/src/hb-subset-cff-common.hh index 4039f9c95..c3f7b40c8 100644 --- a/src/hb-subset-cff-common.hh +++ b/src/hb-subset-cff-common.hh @@ -1128,7 +1128,7 @@ struct subr_subsetter_t if (opstr.op == OpCode_callsubr || opstr.op == OpCode_callgsubr) size += 3; } - if (!buff.alloc (buff.length + size, true)) + if (!buff.alloc_exact (buff.length + size)) return false; for (auto &opstr : str.values) diff --git a/src/hb-subset-cff1.cc b/src/hb-subset-cff1.cc index e9dd5d642..d080e0a27 100644 --- a/src/hb-subset-cff1.cc +++ b/src/hb-subset-cff1.cc @@ -45,7 +45,7 @@ struct remap_sid_t void alloc (unsigned size) { map.alloc (size); - vector.alloc (size, true); + vector.alloc_exact (size); } bool in_error () const diff --git a/src/hb-subset.cc b/src/hb-subset.cc index 4e96c9853..fbdf1b4f9 100644 --- a/src/hb-subset.cc +++ b/src/hb-subset.cc @@ -296,7 +296,7 @@ _try_subset (const TableType *table, HB_UNTAG (c->table_tag), buf_size); if (unlikely (buf_size > c->source_blob->length * 256 || - !buf->alloc (buf_size, true))) + !buf->alloc_exact (buf_size))) { DEBUG_MSG (SUBSET, nullptr, "OT::%c%c%c%c failed to reallocate %u bytes.", HB_UNTAG (c->table_tag), buf_size); diff --git a/src/hb-vector.hh b/src/hb-vector.hh index c0cc7063f..5d3e12cb0 100644 --- a/src/hb-vector.hh +++ b/src/hb-vector.hh @@ -62,19 +62,19 @@ struct hb_vector_t } hb_vector_t (const hb_vector_t &o) : hb_vector_t () { - alloc (o.length, true); + alloc_exact (o.length); if (unlikely (in_error ())) return; copy_array (o.as_array ()); } hb_vector_t (array_t o) : hb_vector_t () { - alloc (o.length, true); + alloc_exact (o.length); if (unlikely (in_error ())) return; copy_array (o); } hb_vector_t (c_array_t o) : hb_vector_t () { - alloc (o.length, true); + alloc_exact (o.length); if (unlikely (in_error ())) return; copy_array (o); } @@ -132,7 +132,7 @@ struct hb_vector_t hb_vector_t& operator = (const hb_vector_t &o) { reset (); - alloc (o.length, true); + alloc_exact (o.length); if (unlikely (in_error ())) return *this; copy_array (o.as_array ()); @@ -432,6 +432,10 @@ struct hb_vector_t return true; } + bool alloc_exact (unsigned int size) + { + return alloc (size, true); + } bool resize (int size_, bool initialize = true, bool exact = false) { @@ -497,7 +501,7 @@ struct hb_vector_t shrink_vector (size); if (shrink_memory) - alloc (size, true); /* To force shrinking memory if needed. */ + alloc_exact (size); /* To force shrinking memory if needed. */ }