mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-08-15 13:27:53 +00:00
lib: significantly improve nb cli command sorting
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>
This commit is contained in:
parent
a8f67b1306
commit
0de76236b1
@ -550,6 +550,13 @@ void nb_cli_show_config_prepare(struct nb_config *config, bool with_defaults)
|
|||||||
LYD_VALIDATE_NO_STATE, NULL);
|
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,
|
static void show_dnode_children_cmds(struct vty *vty, struct lyd_node *root,
|
||||||
bool with_defaults)
|
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.
|
* it's time to print the config.
|
||||||
*/
|
*/
|
||||||
if (sort_node && nb_node != sort_node) {
|
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))
|
for (ALL_LIST_ELEMENTS_RO(sort_list, listnode, data))
|
||||||
nb_cli_show_dnode_cmds(vty, data,
|
nb_cli_show_dnode_cmds(vty, data,
|
||||||
with_defaults);
|
with_defaults);
|
||||||
@ -584,11 +595,9 @@ static void show_dnode_children_cmds(struct vty *vty, struct lyd_node *root,
|
|||||||
if (!sort_node) {
|
if (!sort_node) {
|
||||||
sort_node = nb_node;
|
sort_node = nb_node;
|
||||||
sort_list = list_new();
|
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;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -596,6 +605,9 @@ static void show_dnode_children_cmds(struct vty *vty, struct lyd_node *root,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (sort_node) {
|
if (sort_node) {
|
||||||
|
list_sort(sort_list,
|
||||||
|
(int (*)(const void **, const void **))lyd_node_cmp);
|
||||||
|
|
||||||
for (ALL_LIST_ELEMENTS_RO(sort_list, listnode, data))
|
for (ALL_LIST_ELEMENTS_RO(sort_list, listnode, data))
|
||||||
nb_cli_show_dnode_cmds(vty, data, with_defaults);
|
nb_cli_show_dnode_cmds(vty, data, with_defaults);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user