/* * Clean data of keys array */ void clean_keys_array(const struct bwstring *s, struct keys_array *ka) { if (ka) { for (size_t i = 0; i < keys_num; ++i) if (ka->key[i].k && ka->key[i].k != s) bwsfree(ka->key[i].k); memset(ka, 0, keys_array_size()); } }
/* * De-allocate a sort list item object memory */ void sort_list_item_clean(struct sort_list_item *si) { if (si) { clean_keys_array(si->str, &(si->ka)); if (si->str) { bwsfree(si->str); si->str = NULL; } } }
/* * Set value of a key in the keys set */ void set_key_on_keys_array(struct keys_array *ka, struct bwstring *s, size_t ind) { if (ka && keys_num > ind) { struct key_value *kv; kv = get_key_from_keys_array(ka, ind); if (kv->k && kv->k != s) bwsfree(kv->k); kv->k = s; } }
/* * Clean data of keys array */ void clean_keys_array(const struct bwstring *s, struct keys_array *ka) { if (ka) { for (size_t i = 0; i < keys_num; ++i) { const struct key_value *kv; kv = get_key_from_keys_array(ka, i); if (kv->k && kv->k != s) bwsfree(kv->k); } memset(ka, 0, keys_array_size()); } }
/* * Set value of a sort list item. * Return combined string and keys memory size. */ void sort_list_item_set(struct sort_list_item *si, struct bwstring *str) { if (si) { clean_keys_array(si->str, &(si->ka)); if (si->str) { if (si->str == str) { /* we are trying to reset the same string */ return; } else { bwsfree(si->str); si->str = NULL; } } si->str = str; sort_list_item_make_key(si); } }