summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorIlya Maximets <i.maximets@ovn.org>2022-08-29 22:52:45 +0200
committerIlya Maximets <i.maximets@ovn.org>2022-08-30 23:51:05 +0200
commit5046f2e35f62838c2ad410e20448e0b7c81d8234 (patch)
tree5b8cfd884db10040c5807f2cbf5c48d04bcfbee0 /lib
parenta32a4e1fa2d3fad284834d4b7bccc2e71d33f9da (diff)
downloadopenvswitch-5046f2e35f62838c2ad410e20448e0b7c81d8234.tar.gz
sset, smap, hmapx: Reserve hash map space while cloning.
This makes the clone a little bit faster by avoiding multiple incremental expansions with re-allocations on big sets. Acked-by: Eelco Chaudron <echaudro@redhat.com> Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
Diffstat (limited to 'lib')
-rw-r--r--lib/hmapx.c2
-rw-r--r--lib/smap.c2
-rw-r--r--lib/sset.c2
3 files changed, 6 insertions, 0 deletions
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);