From 7171917b52880728b513168d946196331b7707d1 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sat, 15 Jan 2022 17:16:40 -0700 Subject: [PATCH] [vector] Construct items when enlarging --- src/hb-vector.hh | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/hb-vector.hh b/src/hb-vector.hh index a474a7ba5..636e125c5 100644 --- a/src/hb-vector.hh +++ b/src/hb-vector.hh @@ -232,6 +232,26 @@ struct hb_vector_t return new_array; } + template ::value)> + void + grow_vector (unsigned size) + { + memset (arrayZ + length, 0, (size - length) * sizeof (*arrayZ)); + length = size; + } + template ::value)> + void + grow_vector (unsigned size) + { + while (length < size) + { + length++; + new (std::addressof (arrayZ[length - 1])) Type (); + } + } + template ::value)> void @@ -294,8 +314,7 @@ struct hb_vector_t return false; if (size > length) - // XXX construct objects. - memset (arrayZ + length, 0, (size - length) * sizeof (*arrayZ)); + grow_vector (size); else if (size < length) shrink_vector (size);