Replace uses of Gee.TreeSet where used for sorting

Add new Geary.Iterable::to_sorted_list method that should be more
performant than adding elements to a sorted set and sorting one-by-one,
use that instead of a TreeSet.
This commit is contained in:
Michael Gratton 2019-11-20 12:46:36 +11:00
parent 37d2898b73
commit 89642c5283
5 changed files with 66 additions and 18 deletions

View file

@ -13,6 +13,7 @@ class Geary.RFC822.MailboxAddressesTest : TestCase {
add_test("from_rfc822_string_quoted", from_rfc822_string_quoted);
add_test("to_rfc822_string", to_rfc822_string);
add_test("equal_to", equal_to);
add_test("hash", hash);
}
public void from_rfc822_string_encoded() throws Error {
@ -82,6 +83,34 @@ class Geary.RFC822.MailboxAddressesTest : TestCase {
);
}
public void hash() throws Error {
var mailboxes_a = new_addreses({ "test1@example.com" });
var mailboxes_b = new_addreses({ "test1@example.com" });
var mailboxes_c = new_addreses({ "test2@example.com" });
assert_true(mailboxes_a.hash() == mailboxes_a.hash());
assert_true(mailboxes_a.hash() == mailboxes_b.hash());
assert_false(mailboxes_a.hash() == mailboxes_c.hash());
assert_true(
new_addreses({ "test1@example.com", "test2@example.com" }).hash() ==
new_addreses({ "test1@example.com", "test2@example.com" }).hash()
);
assert_true(
new_addreses({ "test1@example.com", "test2@example.com" }).hash() ==
new_addreses({ "test2@example.com", "test1@example.com" }).hash()
);
assert_false(
new_addreses({ "test1@example.com", "test2@example.com" }).hash() ==
new_addreses({ "test1@example.com" }).hash()
);
assert_false(
new_addreses({ "test1@example.com", "test2@example.com" }).hash() ==
new_addreses({ "test1@example.com", "test3@example.com" }).hash()
);
}
private MailboxAddresses new_addreses(string[] address_strings) {
Gee.List<MailboxAddress> addresses = new Gee.LinkedList<MailboxAddress>();
foreach (string address in address_strings) {