Skip to content
Snippets Groups Projects
Commit dea89233 authored by Marek Vavrusa's avatar Marek Vavrusa
Browse files

Faster dname equality test.

parent 73d561e6
No related branches found
No related tags found
No related merge requests found
......@@ -585,8 +585,16 @@ int knot_dname_cmp_wire(const knot_dname_t *d1, const knot_dname_t *d2,
bool knot_dname_is_equal(const knot_dname_t *d1, const knot_dname_t *d2)
{
/*! \todo Could be implemented more efficiently, check profile first. */
return (knot_dname_cmp(d1, d2) == 0);
while(*d1 != '\0' || *d2 != '\0') {
if (knot_label_is_equal(d1, d2)) {
d1 = knot_wire_next_label(d1, NULL);
d2 = knot_wire_next_label(d2, NULL);
} else {
return false;
}
}
return true;
}
/*----------------------------------------------------------------------------*/
......
......@@ -27,7 +27,7 @@ static int test_fw(size_t l, const char *w) {
int main(int argc, char *argv[])
{
plan(23);
plan(29);
knot_dname_t *d = NULL, *d2 = NULL;
const char *w = NULL, *t = NULL;
......@@ -149,5 +149,30 @@ int main(int argc, char *argv[])
ok(d == NULL, "dname_parse: bad name");
ok(pos == 0, "dname_parse: bad name (parsed length)");
/* name equality checks */
t = "ab.cd.ef";
d = knot_dname_from_str(t, strlen(t));
ok(knot_dname_is_equal(d, d), "dname_is_equal: equal names");
t = "ab.cd.fe";
d2 = knot_dname_from_str(t, strlen(t));
ok(!knot_dname_is_equal(d, d2), "dname_is_equal: same label count");
knot_dname_free(&d2);
t = "ab.cd";
d2 = knot_dname_from_str(t, strlen(t));
ok(!knot_dname_is_equal(d, d2), "dname_is_equal: len(d1) < len(d2)");
knot_dname_free(&d2);
t = "ab.cd.ef.gh";
d2 = knot_dname_from_str(t, strlen(t));
ok(!knot_dname_is_equal(d, d2), "dname_is_equal: len(d1) > len(d2)");
knot_dname_free(&d2);
t = "ab.cd.efe";
d2 = knot_dname_from_str(t, strlen(t));
ok(!knot_dname_is_equal(d, d2), "dname_is_equal: last label longer");
knot_dname_free(&d2);
t = "ab.cd.e";
d2 = knot_dname_from_str(t, strlen(t));
ok(!knot_dname_is_equal(d, d2), "dname_is_equal: last label shorter");
knot_dname_free(&d2);
return 0;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment