diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2020-09-06 13:23:19 +0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2020-09-06 12:59:54 -0700 |
commit | 754b4a5c9df088015a3f9dc504d51c3108bc7450 (patch) | |
tree | 63b7e2a2d22daab97872c6d340f7f964afe13682 | |
parent | f93acdace7234b727dec830adbaed6b9edb3e6ac (diff) | |
download | subsurface-754b4a5c9df088015a3f9dc504d51c3108bc7450.tar.gz |
cleanup: use taxonomy_index_for_category() in taxonomy_set_category()
Instead of recoding the "search for category" loop, reuse the already
existing functionality.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
-rw-r--r-- | core/taxonomy.c | 19 |
1 files changed, 6 insertions, 13 deletions
diff --git a/core/taxonomy.c b/core/taxonomy.c index e786ba45d..2c11d084d 100644 --- a/core/taxonomy.c +++ b/core/taxonomy.c @@ -83,26 +83,19 @@ const char *taxonomy_get_country(struct taxonomy_data *t) void taxonomy_set_category(struct taxonomy_data *t, enum taxonomy_category category, const char *value, enum taxonomy_origin origin) { - int idx = -1; + int idx = taxonomy_index_for_category(t, category); - // make sure we have taxonomy data allocated - alloc_taxonomy_table(t); - - for (int i = 0; i < t->nr; i++) { - if (t->category[i].category == category) { - free((void *)t->category[i].value); - t->category[i].value = NULL; - idx = i; - break; - } - } - if (idx == -1) { + if (idx < 0) { + alloc_taxonomy_table(t); // make sure we have taxonomy data allocated if (t->nr == TC_NR_CATEGORIES - 1) { // can't add another one fprintf(stderr, "Error adding taxonomy category\n"); return; } idx = t->nr++; + } else { + free((void *)t->category[idx].value); + t->category[idx].value = NULL; } t->category[idx].value = strdup(value); t->category[idx].origin = origin; |