tree_data OPTIMIZE optimize creation of children htable
Here, we know the number of children that will be added in the hash
table, so create the hash table with the correct number of elements to
avoid automatic resizes.
Signed-off-by: Olivier Matz <olivier.matz@6wind.com>
diff --git a/tests/utests/basic/test_hash_table.c b/tests/utests/basic/test_hash_table.c
index f19ff36..78950cd 100644
--- a/tests/utests/basic/test_hash_table.c
+++ b/tests/utests/basic/test_hash_table.c
@@ -171,16 +171,18 @@
/* check all records */
for (i = 0; i < 8; ++i) {
- if (i == 2)
+ if (i == 2) {
assert_int_not_equal(UINT32_MAX, ht->hlists[i].first);
- else
+ } else {
assert_int_equal(UINT32_MAX, ht->hlists[i].first);
+ }
}
for (i = 0; i < 8; ++i) {
- if (i >= 2 && i < 6)
+ if ((i >= 2) && (i < 6)) {
assert_int_equal(LY_SUCCESS, lyht_find(ht, &i, 2, NULL));
- else
+ } else {
assert_int_equal(LY_ENOTFOUND, lyht_find(ht, &i, 2, NULL));
+ }
}
rec_idx = ht->hlists[2].first;
count = 0;
@@ -202,16 +204,18 @@
/* check all records */
for (i = 0; i < 8; ++i) {
- if (i == 2)
+ if (i == 2) {
assert_int_not_equal(UINT32_MAX, ht->hlists[i].first);
- else
+ } else {
assert_int_equal(UINT32_MAX, ht->hlists[i].first);
+ }
}
for (i = 0; i < 8; ++i) {
- if (i == 3 || i == 5)
+ if ((i == 3) || (i == 5)) {
assert_int_equal(LY_SUCCESS, lyht_find(ht, &i, 2, NULL));
- else
+ } else {
assert_int_equal(LY_ENOTFOUND, lyht_find(ht, &i, 2, NULL));
+ }
}
rec_idx = ht->hlists[2].first;
count = 0;
@@ -224,10 +228,11 @@
assert_int_equal(count, 2);
for (i = 0; i < 8; ++i) {
- if (i == 3 || i == 5)
+ if ((i == 3) || (i == 5)) {
assert_int_equal(lyht_find(ht, &i, 2, NULL), LY_SUCCESS);
- else
+ } else {
assert_int_equal(lyht_find(ht, &i, 2, NULL), LY_ENOTFOUND);
+ }
}
i = 3;