From 29d49eced8a9f4a9a6148972b0ba4430a2f7f6bf Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Wed, 1 Nov 2023 15:55:47 -0600 Subject: [PATCH] [vector] Introduce realloc_moves tag Some types (even aggregate) can be moved using realloc(). Extend the fast path to hb_hashmap and tuple_delta_t. --- src/hb-array.hh | 2 ++ src/hb-map.hh | 2 ++ src/hb-ot-var-common.hh | 2 ++ src/hb-vector.hh | 7 ++++--- 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/hb-array.hh b/src/hb-array.hh index 760f90259..9037179bc 100644 --- a/src/hb-array.hh +++ b/src/hb-array.hh @@ -47,6 +47,8 @@ enum hb_not_found_t template struct hb_array_t : hb_iter_with_fallback_t, Type&> { + static constexpr bool realloc_move = true; + /* * Constructors. */ diff --git a/src/hb-map.hh b/src/hb-map.hh index 13d62054c..a692b21e4 100644 --- a/src/hb-map.hh +++ b/src/hb-map.hh @@ -42,6 +42,8 @@ template struct hb_hashmap_t { + static constexpr bool realloc_move = true; + hb_hashmap_t () { init (); } ~hb_hashmap_t () { fini (); } diff --git a/src/hb-ot-var-common.hh b/src/hb-ot-var-common.hh index 6b4dc5c65..b62458c9f 100644 --- a/src/hb-ot-var-common.hh +++ b/src/hb-ot-var-common.hh @@ -434,6 +434,8 @@ enum packed_delta_flag_t struct tuple_delta_t { + static constexpr bool realloc_move = true; // Watch out when adding new members! + public: hb_hashmap_t axis_tuples; diff --git a/src/hb-vector.hh b/src/hb-vector.hh index 13cfe56b5..dfe1b7d1c 100644 --- a/src/hb-vector.hh +++ b/src/hb-vector.hh @@ -37,6 +37,8 @@ template struct hb_vector_t { + static constexpr bool realloc_move = true; + typedef Type item_t; static constexpr unsigned item_size = hb_static_size (Type); using array_t = typename std::conditional, hb_array_t>::type; @@ -268,10 +270,9 @@ struct hb_vector_t } return new_array; } - /* Specialization for hb_vector_t> to speed up. */ + /* Specialization for types that can be moved using realloc(). */ template ) || - hb_is_same (T, hb_array_t ))> + hb_enable_if (T::realloc_move)> Type * realloc_vector (unsigned new_allocated, hb_priority<1>) {