]> git.puffer.fish Git - mirror/frr.git/commitdiff
lib: nb_notif: notification selectors sorted with no dups 18683/head
authorChristian Hopps <chopps@labn.net>
Tue, 1 Apr 2025 03:18:42 +0000 (03:18 +0000)
committerChristian Hopps <chopps@labn.net>
Mon, 21 Apr 2025 09:22:28 +0000 (09:22 +0000)
Signed-off-by: Christian Hopps <chopps@labn.net>
lib/northbound_notif.c

index 746b33beb2232682f81b64cfd74f3473347345db..14da819375d09261d5427d4bf8d6d29edb47ecf7 100644 (file)
@@ -692,15 +692,28 @@ static void nb_notif_set_walk_timer(void)
 
 void nb_notif_set_filters(const char **selectors, bool replace)
 {
+       // struct nb_node **np, **nb_nodes;
        const char **csp;
+       bool exists;
+       int before;
 
-       if (replace) {
+       if (replace)
                darr_free_free(nb_notif_filters);
-               nb_notif_filters = selectors;
-               return;
+
+       /* Add in sorted, eliminating duplicates */
+       darr_foreach_p (selectors, csp) {
+               if (!darr_len(nb_notif_filters)) {
+                       *darr_append(nb_notif_filters) = *csp;
+                       continue;
+               }
+               exists = false;
+               before = darr_str_search_ceil(nb_notif_filters, *csp, &exists);
+               if (exists)
+                       darr_free(*csp);
+               else
+                       *darr_insert(nb_notif_filters, before) = *csp;
        }
-       darr_foreach_p (selectors, csp)
-               *darr_append(nb_notif_filters) = *csp;
+
        darr_free(selectors);
 }