This makes the clone a little bit faster by avoiding multiple incremental expansions with re-allocations on big sets.
Signed-off-by: Ilya Maximets <[email protected]> --- lib/hmapx.c | 2 ++ lib/smap.c | 2 ++ lib/sset.c | 2 ++ 3 files changed, 6 insertions(+) diff --git a/lib/hmapx.c b/lib/hmapx.c index 68192fc2c..bb9ec11c5 100644 --- a/lib/hmapx.c +++ b/lib/hmapx.c @@ -66,6 +66,8 @@ hmapx_clone(struct hmapx *map, const struct hmapx *orig) struct hmapx_node *node; hmapx_init(map); + hmap_reserve(&map->map, hmapx_count(orig)); + HMAP_FOR_EACH (node, hmap_node, &orig->map) { hmapx_add__(map, node->data, node->hmap_node.hash); } diff --git a/lib/smap.c b/lib/smap.c index b23eeb52d..c1633e2a1 100644 --- a/lib/smap.c +++ b/lib/smap.c @@ -310,6 +310,8 @@ smap_clone(struct smap *dst, const struct smap *src) const struct smap_node *node; smap_init(dst); + hmap_reserve(&dst->map, smap_count(src)); + SMAP_FOR_EACH (node, src) { smap_add__(dst, xstrdup(node->key), xstrdup(node->value), node->node.hash); diff --git a/lib/sset.c b/lib/sset.c index 6fbaa9d60..aa1790020 100644 --- a/lib/sset.c +++ b/lib/sset.c @@ -79,6 +79,8 @@ sset_clone(struct sset *set, const struct sset *orig) struct sset_node *node; sset_init(set); + hmap_reserve(&set->map, sset_count(orig)); + HMAP_FOR_EACH (node, hmap_node, &orig->map) { sset_add__(set, node->name, strlen(node->name), node->hmap_node.hash); -- 2.34.3 _______________________________________________ dev mailing list [email protected] https://mail.openvswitch.org/mailman/listinfo/ovs-dev
