/** Given a sorted smartlist <b>sl</b> and the comparison function used to
* sort it, remove all duplicate members. If free_fn is provided, calls
- * free_fn on each duplicate. Otherwise, frees them with tor_free(), which
- * may not be what you want.. Preserves order.
+ * free_fn on each duplicate. Otherwise, just removes them. Preserves order.
*/
void
smartlist_uniq(smartlist_t *sl,
(const void **)&(sl->list[i])) == 0) {
if (free_fn)
free_fn(sl->list[i]);
- else
- tor_free(sl->list[i]);
smartlist_del_keeporder(sl, i--);
}
}
void
smartlist_uniq_strings(smartlist_t *sl)
{
- smartlist_uniq(sl, _compare_string_ptrs, NULL);
+ smartlist_uniq(sl, _compare_string_ptrs, _tor_free);
}
/* Heap-based priority queue implementation for O(lg N) insert and remove.
void
smartlist_uniq_digests(smartlist_t *sl)
{
- smartlist_uniq(sl, _compare_digests, NULL);
+ smartlist_uniq(sl, _compare_digests, _tor_free);
}
#define DEFINE_MAP_STRUCTS(maptype, keydecl, prefix) \
smartlist_sort(versions, _compare_tor_version_str_ptr);
if (remove_duplicates)
- smartlist_uniq(versions, _compare_tor_version_str_ptr, NULL);
+ smartlist_uniq(versions, _compare_tor_version_str_ptr, _tor_free);
}
"50,noon,radar,a,man,a,plan,a,canal,panama,radar,noon,50",
",", 0, 0);
smartlist_sort(sl, _compare_strs);
- smartlist_uniq(sl, _compare_strs, NULL);
+ smartlist_uniq(sl, _compare_strs, _tor_free);
cp = smartlist_join_strings(sl, ",", 0, NULL);
test_streq(cp, "50,a,canal,man,noon,panama,plan,radar");
tor_free(cp);