From c58bfa35fb9d6d8bebad94c2c6e24eaf18d5d1d5 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sat, 15 Jan 2022 18:06:03 -0700 Subject: [PATCH] [vector] Move semantics in vector remove() --- src/hb-vector.hh | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/src/hb-vector.hh b/src/hb-vector.hh index 11a9f5a41..9fb477cb0 100644 --- a/src/hb-vector.hh +++ b/src/hb-vector.hh @@ -271,6 +271,23 @@ struct hb_vector_t } } + template ::value)> + void + shift_down_vector (unsigned i) + { + memmove (static_cast (&arrayZ[i - 1]), + static_cast (&arrayZ[i]), + (length - i) * sizeof (Type)); + } + template ::value)> + void + shift_down_vector (unsigned i) + { + for (; i < length; i++) + arrayZ[i - 1] = std::move (arrayZ[i]); + } /* Allocate for size but don't adjust length. */ bool alloc (unsigned int size) @@ -335,10 +352,8 @@ struct hb_vector_t { if (unlikely (i >= length)) return; - // XXX Swap / move / destruct. - memmove (static_cast (&arrayZ[i]), - static_cast (&arrayZ[i + 1]), - (length - i - 1) * sizeof (Type)); + arrayZ[i].~Type (); + shift_down_vector (i + 1); length--; }