From 4c6fd7cdb2f2ab60de83d9a1e0fd189510b771a0 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 1 Nov 2021 23:13:34 -0600 Subject: [PATCH] [map] Try moving items when resizing --- src/hb-map.hh | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/hb-map.hh b/src/hb-map.hh index 196b8e76a..696cb8713 100644 --- a/src/hb-map.hh +++ b/src/hb-map.hh @@ -159,17 +159,15 @@ struct hb_hashmap_t if (old_items[i].is_real ()) set_with_hash (old_items[i].key, old_items[i].hash, - old_items[i].value); + hb_move (old_items[i].value)); hb_free (old_items); return true; } - bool set (K key, V value) - { - return set_with_hash (key, hb_hash (key), value); - } + bool set (K key, const V& value) { return set_with_hash (key, hb_hash (key), value); } + bool set (K key, V&& value) { return set_with_hash (key, hb_hash (key), hb_move (value)); } V get (K key) const { @@ -239,7 +237,8 @@ struct hb_hashmap_t protected: - bool set_with_hash (K key, uint32_t hash, V value) + template + bool set_with_hash (K key, uint32_t hash, VV&& value) { if (unlikely (!successful)) return false; if (unlikely (key == kINVALID)) return true;