]> git.proxmox.com Git - mirror_frr.git/commitdiff
lib: nexthop_group_equal() assume ordered
authorStephen Worley <sworley@cumulusnetworks.com>
Tue, 6 Aug 2019 17:40:19 +0000 (13:40 -0400)
committerStephen Worley <sworley@cumulusnetworks.com>
Fri, 25 Oct 2019 15:13:42 +0000 (11:13 -0400)
Speed up nexthop_group_equal() by making it assume the
groups it has been passed are ordered. This should always
be the case.

Signed-off-by: Stephen Worley <sworley@cumulusnetworks.com>
lib/nexthop_group.c

index a79b2741c5486b2dbef5636f6a998f095039d644..fb569360c486430d78bb08521bf22978d3a27293 100644 (file)
@@ -132,10 +132,12 @@ struct nexthop *nexthop_exists(const struct nexthop_group *nhg,
        return NULL;
 }
 
+/* This assumes ordered */
 bool nexthop_group_equal(const struct nexthop_group *nhg1,
                         const struct nexthop_group *nhg2)
 {
-       struct nexthop *nh = NULL;
+       struct nexthop *nh1 = NULL;
+       struct nexthop *nh2 = NULL;
 
        if (nhg1 && !nhg2)
                return false;
@@ -147,8 +149,9 @@ bool nexthop_group_equal(const struct nexthop_group *nhg1,
            != nexthop_group_nexthop_num_no_recurse(nhg2))
                return false;
 
-       for (nh = nhg1->nexthop; nh; nh = nh->next) {
-               if (!nexthop_exists(nhg2, nh))
+       for (nh1 = nhg1->nexthop, nh2 = nhg2->nexthop; nh1 && nh2;
+            nh1 = nh1->next, nh2 = nh2->next) {
+               if (!nexthop_same(nh1, nh2))
                        return false;
        }