summaryrefslogtreecommitdiffstats
path: root/libnetdata
diff options
context:
space:
mode:
authorCosta Tsaousis <costa@netdata.cloud>2022-06-02 08:55:02 +0300
committerGitHub <noreply@github.com>2022-06-02 08:55:02 +0300
commit04b1c9e0dadbea871ca51342be8e71265c40034d (patch)
tree8727e0a2d781d375e5cdca576301b334f11f91d5 /libnetdata
parent155bebf55ad55e3b884658039499c3935759815c (diff)
dictionary improvements (#13052)
* fix typo in foreach write; added unit tests to traverse empty dictionaries * rename variable dfe in macro to be uniform with name variable
Diffstat (limited to 'libnetdata')
-rw-r--r--libnetdata/dictionary/dictionary.c2
-rw-r--r--libnetdata/dictionary/dictionary.h10
2 files changed, 7 insertions, 5 deletions
diff --git a/libnetdata/dictionary/dictionary.c b/libnetdata/dictionary/dictionary.c
index de182cb023..1293491651 100644
--- a/libnetdata/dictionary/dictionary.c
+++ b/libnetdata/dictionary/dictionary.c
@@ -1253,6 +1253,8 @@ int dictionary_unittest(size_t entries) {
dict = dictionary_create(DICTIONARY_FLAG_WITH_STATISTICS|DICTIONARY_FLAG_NAME_LINK_DONT_CLONE|DICTIONARY_FLAG_VALUE_LINK_DONT_CLONE|DICTIONARY_FLAG_DONT_OVERWRITE_VALUE);
dictionary_unittest_run_and_measure_time(dict, "adding entries", names, values, entries, &errors, dictionary_unittest_set_nonclone);
dictionary_unittest_run_and_measure_time(dict, "foreach write delete this", names, values, entries, &errors, dictionary_unittest_foreach_delete_this);
+ dictionary_unittest_run_and_measure_time(dict, "traverse foreach read loop empty", names, values, 0, &errors, dictionary_unittest_foreach);
+ dictionary_unittest_run_and_measure_time(dict, "walkthrough read callback empty", names, values, 0, &errors, dictionary_unittest_walkthrough);
dictionary_unittest_run_and_measure_time(dict, "destroying empty dictionary", names, values, entries, &errors, dictionary_unittest_destroy);
dictionary_unittest_free_char_pp(names, entries);
diff --git a/libnetdata/dictionary/dictionary.h b/libnetdata/dictionary/dictionary.h
index 1aeeb78f3c..7b9da3a380 100644
--- a/libnetdata/dictionary/dictionary.h
+++ b/libnetdata/dictionary/dictionary.h
@@ -154,17 +154,17 @@ typedef DICTFE_CONST struct dictionary_foreach {
} DICTFE;
#define dfe_start_read(dict, value) dfe_start_rw(dict, value, 'r')
-#define dfe_start_write(dict, value) dfe_start_rw(dict, value, 'r')
+#define dfe_start_write(dict, value) dfe_start_rw(dict, value, 'w')
#define dfe_start_rw(dict, value, mode) \
do { \
- DICTFE dfe_ ## value = {}; \
+ DICTFE value ## _dfe = {}; \
const char *value ## _name; (void)(value ## _name); \
- for((value) = dictionary_foreach_start_rw(&dfe_ ## value, (dict), (mode)), ( value ## _name ) = dfe_ ## value.name; \
+ for((value) = dictionary_foreach_start_rw(&value ## _dfe, (dict), (mode)), ( value ## _name ) = value ## _dfe.name; \
(value) ;\
- (value) = dictionary_foreach_next(&dfe_ ## value), ( value ## _name ) = dfe_ ## value.name)
+ (value) = dictionary_foreach_next(&value ## _dfe), ( value ## _name ) = value ## _dfe.name)
#define dfe_done(value) \
- dictionary_foreach_done(&dfe_ ## value); \
+ dictionary_foreach_done(&value ## _dfe); \
} while(0)
extern void * dictionary_foreach_start_rw(DICTFE *dfe, DICTIONARY *dict, char rw);