From 5872bdf64ddbf99f7863da382f79ab408cd99e8c Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Fri, 26 May 2023 11:41:54 -0600 Subject: [PATCH] [vector] Add copy-constructor for array_t's --- src/OT/glyf/Glyph.hh | 2 +- src/hb-vector.hh | 22 +++++++++++++++++----- src/test-vector.cc | 5 +++++ 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/src/OT/glyf/Glyph.hh b/src/OT/glyf/Glyph.hh index 5f506608b..73c64411c 100644 --- a/src/OT/glyf/Glyph.hh +++ b/src/OT/glyf/Glyph.hh @@ -381,7 +381,7 @@ struct Glyph if (points_with_deltas != nullptr && depth == 0 && type == COMPOSITE) { if (unlikely (!points_with_deltas->resize (points.length))) return false; - points_with_deltas->copy_vector (points); + *points_with_deltas = points; } switch (type) { diff --git a/src/hb-vector.hh b/src/hb-vector.hh index d61ce48c0..935ade5b3 100644 --- a/src/hb-vector.hh +++ b/src/hb-vector.hh @@ -62,7 +62,19 @@ struct hb_vector_t { alloc (o.length, true); if (unlikely (in_error ())) return; - copy_vector (o); + copy_array (o.as_array ()); + } + hb_vector_t (array_t o) : hb_vector_t () + { + alloc (o.length, true); + if (unlikely (in_error ())) return; + copy_array (o); + } + hb_vector_t (c_array_t o) : hb_vector_t () + { + alloc (o.length, true); + if (unlikely (in_error ())) return; + copy_array (o); } hb_vector_t (hb_vector_t &&o) { @@ -119,7 +131,7 @@ struct hb_vector_t alloc (o.length, true); if (unlikely (in_error ())) return *this; - copy_vector (o); + copy_array (o.as_array ()); return *this; } @@ -287,7 +299,7 @@ struct hb_vector_t template void - copy_vector (const hb_vector_t &other) + copy_array (hb_array_t other) { length = other.length; if (!HB_OPTIMIZE_SIZE_VAL && sizeof (T) >= sizeof (long long)) @@ -301,7 +313,7 @@ struct hb_vector_t hb_enable_if (!hb_is_trivially_copyable (T) && std::is_copy_constructible::value)> void - copy_vector (const hb_vector_t &other) + copy_array (hb_array_t other) { length = 0; while (length < other.length) @@ -316,7 +328,7 @@ struct hb_vector_t std::is_default_constructible::value && std::is_copy_assignable::value)> void - copy_vector (const hb_vector_t &other) + copy_array (hb_array_t other) { length = 0; while (length < other.length) diff --git a/src/test-vector.cc b/src/test-vector.cc index 65e51c657..cc8ceabd1 100644 --- a/src/test-vector.cc +++ b/src/test-vector.cc @@ -176,6 +176,11 @@ main (int argc, char **argv) assert (s.get_population () == 0); } + { + hb_vector_t v; + hb_map_t m; + v.push (m); + } { hb_vector_t v; hb_map_t m;