return strcmp(nhgc1->name, nhgc2->name);
}
+static struct nexthop *nexthop_group_tail(const struct nexthop_group *nhg)
+{
+ struct nexthop *nexthop = nhg->nexthop;
+
+ while (nexthop && nexthop->next)
+ nexthop = nexthop->next;
+
+ return nexthop;
+}
+
uint8_t nexthop_group_nexthop_num(const struct nexthop_group *nhg)
{
struct nexthop *nhop;
void _nexthop_group_add_sorted(struct nexthop_group *nhg,
struct nexthop *nexthop)
{
- struct nexthop *position, *prev;
+ struct nexthop *position, *prev, *tail;
+
+ /* Try to just append to the end first
+ * This trust it is already sorted
+ */
+
+ tail = nexthop_group_tail(nhg);
+
+ if (tail && (nexthop_cmp(tail, nexthop) < 0)) {
+ tail->next = nexthop;
+ nexthop->prev = tail;
+
+ return;
+ }
for (position = nhg->nexthop, prev = NULL; position;
prev = position, position = position->next) {