From d36b87bde4ff91ad0eb0dbb19c7183c7d6d46d81 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Fri, 23 Jun 2023 14:42:21 -0600 Subject: [PATCH] [vector] Speed up hb_vector_t>::realloc_vector Use in CFF subsetting. --- src/hb-vector.hh | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/hb-vector.hh b/src/hb-vector.hh index e2263492b..8c8409d17 100644 --- a/src/hb-vector.hh +++ b/src/hb-vector.hh @@ -255,7 +255,7 @@ struct hb_vector_t template Type * - realloc_vector (unsigned new_allocated) + realloc_vector (unsigned new_allocated, hb_priority<0>) { if (!new_allocated) { @@ -267,7 +267,7 @@ struct hb_vector_t template Type * - realloc_vector (unsigned new_allocated) + realloc_vector (unsigned new_allocated, hb_priority<0>) { if (!new_allocated) { @@ -287,6 +287,19 @@ struct hb_vector_t } return new_array; } + /* Specialization for hb_vector_t> to speed up. */ + template ))> + Type * + realloc_vector (unsigned new_allocated, hb_priority<1>) + { + if (!new_allocated) + { + hb_free (arrayZ); + return nullptr; + } + return (Type *) hb_realloc (arrayZ, new_allocated * sizeof (Type)); + } template @@ -418,7 +431,7 @@ struct hb_vector_t return false; } - Type *new_array = realloc_vector (new_allocated); + Type *new_array = realloc_vector (new_allocated, hb_prioritize); if (unlikely (new_allocated && !new_array)) {