From 13ee8edf06d5df7681cc0f4be7479e633a681445 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 24 Feb 2025 21:17:58 -0700 Subject: [PATCH] [vector] Speed up extend() --- src/hb-vector.hh | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/hb-vector.hh b/src/hb-vector.hh index 8748f8d44..679c92151 100644 --- a/src/hb-vector.hh +++ b/src/hb-vector.hh @@ -64,7 +64,14 @@ struct hb_vector_t auto iter = hb_iter (o); if (iter.is_random_access_iterator || iter.has_fast_len) alloc (hb_len (iter), true); - hb_copy (iter, *this); + while (iter) + { + if (!alloc (length + 1)) + break; + unsigned room = allocated - length; + for (unsigned i = 0; i < room && iter; i++) + push_has_room (*iter++); + } } hb_vector_t (const hb_vector_t &o) : hb_vector_t () { @@ -224,6 +231,10 @@ struct hb_vector_t // reference to it. return std::addressof (Crap (Type)); + return push_has_room (std::forward (args)...); + } + template Type *push_has_room (Args&&... args) + { /* Emplace. */ Type *p = std::addressof (arrayZ[length++]); return new (p) Type (std::forward (args)...);