From f839bd11d250b953712733bdb3187eec3bf67419 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 22 Jun 2023 17:29:57 -0600 Subject: [PATCH] [multimap] Use one fewer object Also fix error-checking to check for sub-object errors. --- src/hb-multimap.hh | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/src/hb-multimap.hh b/src/hb-multimap.hh index 42d6c8aae..041562f14 100644 --- a/src/hb-multimap.hh +++ b/src/hb-multimap.hh @@ -38,10 +38,10 @@ struct hb_multimap_t { void add (hb_codepoint_t k, hb_codepoint_t v) { - hb_codepoint_t *i; - if (multiples_indices.has (k, &i)) + hb_vector_t *m; + if (multiples.has (k, &m)) { - multiples_values[*i].push (v); + m->push (v); return; } @@ -51,12 +51,7 @@ struct hb_multimap_t hb_codepoint_t old = *old_v; singulars.del (k); - multiples_indices.set (k, multiples_values.length); - auto *vec = multiples_values.push (); - - vec->push (old); - vec->push (v); - + multiples.set (k, hb_vector_t {old, v}); return; } @@ -69,16 +64,21 @@ struct hb_multimap_t if (singulars.has (k, &v)) return hb_array (v, 1); - hb_codepoint_t *i; - if (multiples_indices.has (k, &i)) - return multiples_values[*i].as_array (); + hb_vector_t *m; + if (multiples.has (k, &m)) + return m->as_array (); return hb_array_t (); } bool in_error () const { - return singulars.in_error () || multiples_indices.in_error () || multiples_values.in_error (); + if (singulars.in_error () || multiples.in_error ()) + return true; + for (const auto &m : multiples.values_ref ()) + if (m.in_error ()) + return true; + return false; } void resize (unsigned size) @@ -88,8 +88,7 @@ struct hb_multimap_t protected: hb_map_t singulars; - hb_map_t multiples_indices; - hb_vector_t> multiples_values; + hb_hashmap_t> multiples; };