]> git.puffer.fish Git - mirror/frr.git/commitdiff
lib: significantly improve nb cli command sorting 9629/head
authorIgor Ryzhov <iryzhov@nfware.com>
Thu, 16 Sep 2021 15:37:12 +0000 (18:37 +0300)
committerIgor Ryzhov <iryzhov@nfware.com>
Fri, 17 Sep 2021 09:00:58 +0000 (12:00 +0300)
Instead of sorting each command one-by-one using listnode_add_sort, add
them to the list without sorting and then sort the list only once.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
lib/northbound_cli.c

index b74a0e6c2300e3ed3cee8aca8adeef7ef8790cd5..6676c0b072170f5991fb81214e8aff5eaf315be7 100644 (file)
@@ -550,6 +550,13 @@ void nb_cli_show_config_prepare(struct nb_config *config, bool with_defaults)
                                       LYD_VALIDATE_NO_STATE, NULL);
 }
 
+static int lyd_node_cmp(struct lyd_node **dnode1, struct lyd_node **dnode2)
+{
+       struct nb_node *nb_node = (*dnode1)->schema->priv;
+
+       return nb_node->cbs.cli_cmp(*dnode1, *dnode2);
+}
+
 static void show_dnode_children_cmds(struct vty *vty, struct lyd_node *root,
                                     bool with_defaults)
 {
@@ -567,6 +574,10 @@ static void show_dnode_children_cmds(struct vty *vty, struct lyd_node *root,
                 * it's time to print the config.
                 */
                if (sort_node && nb_node != sort_node) {
+                       list_sort(sort_list,
+                                 (int (*)(const void **,
+                                          const void **))lyd_node_cmp);
+
                        for (ALL_LIST_ELEMENTS_RO(sort_list, listnode, data))
                                nb_cli_show_dnode_cmds(vty, data,
                                                       with_defaults);
@@ -584,11 +595,9 @@ static void show_dnode_children_cmds(struct vty *vty, struct lyd_node *root,
                        if (!sort_node) {
                                sort_node = nb_node;
                                sort_list = list_new();
-                               sort_list->cmp = (int (*)(void *, void *))
-                                                nb_node->cbs.cli_cmp;
                        }
 
-                       listnode_add_sort(sort_list, child);
+                       listnode_add(sort_list, child);
                        continue;
                }
 
@@ -596,6 +605,9 @@ static void show_dnode_children_cmds(struct vty *vty, struct lyd_node *root,
        }
 
        if (sort_node) {
+               list_sort(sort_list,
+                         (int (*)(const void **, const void **))lyd_node_cmp);
+
                for (ALL_LIST_ELEMENTS_RO(sort_list, listnode, data))
                        nb_cli_show_dnode_cmds(vty, data, with_defaults);