From efa2a5796ef06fd035bd58a573c249f90a141ead Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 24 May 2022 16:24:00 -0600 Subject: [PATCH] [map] Add hb_map_copy() New API: + hb_map_copy() --- docs/harfbuzz-sections.txt | 1 + src/hb-map.cc | 19 +++++++++++++++++++ src/hb-map.h | 3 +++ src/hb-set.cc | 1 + 4 files changed, 24 insertions(+) diff --git a/docs/harfbuzz-sections.txt b/docs/harfbuzz-sections.txt index c08b067e5..d02909784 100644 --- a/docs/harfbuzz-sections.txt +++ b/docs/harfbuzz-sections.txt @@ -453,6 +453,7 @@ hb_icu_script_to_script HB_MAP_VALUE_INVALID hb_map_allocation_successful hb_map_clear +hb_map_copy hb_map_create hb_map_del hb_map_destroy diff --git a/src/hb-map.cc b/src/hb-map.cc index de36bc1de..7335ff421 100644 --- a/src/hb-map.cc +++ b/src/hb-map.cc @@ -172,6 +172,25 @@ hb_map_allocation_successful (const hb_map_t *map) return map->successful; } +/** + * hb_map_copy: + * @map: A map + * + * Allocate a copy of @map. + * + * Return value: Newly-allocated map. + * + * Since: REPLACEME + **/ +hb_map_t * +hb_map_copy (const hb_map_t *map) +{ + hb_map_t *copy = hb_map_create (); + if (unlikely (!copy)) return nullptr; + copy->resize (map->population); + hb_copy (*map, *copy); + return copy; +} /** * hb_map_set: diff --git a/src/hb-map.h b/src/hb-map.h index b45f11ef9..41d877d6a 100644 --- a/src/hb-map.h +++ b/src/hb-map.h @@ -82,6 +82,9 @@ hb_map_get_user_data (hb_map_t *map, HB_EXTERN hb_bool_t hb_map_allocation_successful (const hb_map_t *map); +HB_EXTERN hb_map_t * +hb_map_copy (const hb_map_t *map); + HB_EXTERN void hb_map_clear (hb_map_t *map); diff --git a/src/hb-set.cc b/src/hb-set.cc index d5d44d92a..42788b2bc 100644 --- a/src/hb-set.cc +++ b/src/hb-set.cc @@ -186,6 +186,7 @@ hb_set_t * hb_set_copy (const hb_set_t *set) { hb_set_t *copy = hb_set_create (); + if (unlikely (!copy)) return nullptr; copy->set (*set); return copy; }