From f15858be5f09a9fdfbec9ccc68490e23e5db35ad Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 1 Nov 2021 20:26:07 -0600 Subject: [PATCH] [vector] Pre-allocate if iterator has random-access length --- src/hb-vector.hh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/hb-vector.hh b/src/hb-vector.hh index 92c74dc13..acd66a7fc 100644 --- a/src/hb-vector.hh +++ b/src/hb-vector.hh @@ -51,6 +51,8 @@ struct hb_vector_t hb_requires (hb_is_iterable (Iterable))> hb_vector_t (const Iterable &o) : hb_vector_t () { + if (hb_iter (o).is_random_access_iterator) + alloc (hb_len (hb_iter (o))); hb_copy (o, *this); } hb_vector_t (const hb_vector_t &o) : hb_vector_t ()