mirror of
https://github.com/storytold/harfbuzz.git
synced 2026-11-21 15:01:01 +01:00
Merge pull request #5565 from harfbuzz/vector-resize-simplify
[vector] Simplify resize()
This commit is contained in:
14 files changed
+55
-45
No files matched your search
@@ -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++)
|
||||
{
|
||||
|
||||
@@ -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);
|
||||
|
||||
+1
-1
@@ -176,7 +176,7 @@ struct hb_inc_bimap_t
|
||||
{
|
||||
hb_codepoint_t count = get_population ();
|
||||
hb_vector_t <hb_codepoint_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];
|
||||
|
||||
+4
-4
@@ -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;
|
||||
|
||||
|
||||
+2
-2
@@ -168,7 +168,7 @@ _hb_kbts_shape (hb_shape_plan_t *shape_plan,
|
||||
}
|
||||
|
||||
hb_vector_t<kbts_glyph> 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;
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
+14
-14
@@ -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<unsigned char> &compiled_deltas, /* OUT */
|
||||
hb_vector_t<int> &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<int> &rounded_x_deltas = scratch.rounded_x_deltas;
|
||||
hb_vector_t<int> &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;
|
||||
|
||||
@@ -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++)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -136,7 +136,7 @@ static bool rotate_array (const hb_array_t<const 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<const contour_point_t> contour_points
|
||||
hb_vector_t<double>& 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<double> &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<const contour_point_t> conto
|
||||
hb_vector_t<int> 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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
+13
-3
@@ -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 ()
|
||||
|
||||
Reference in new issue
Block a user