From c17784cfe9fbf384b24da251c78fe146118d5975 Mon Sep 17 00:00:00 2001 From: Olof hagsand Date: Thu, 16 May 2019 20:08:25 +0200 Subject: [PATCH] Removed O(n^2) in cli expand/completion code --- CHANGELOG.md | 1 + apps/cli/cli_show.c | 43 ++++++++----------------------------------- 2 files changed, 9 insertions(+), 35 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e1d8b985..f1af4285 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -42,6 +42,7 @@ * CLICON_XML_CHANGELOG enables the yang changelog feature * CLICON_XML_CHANGELOG_FILE where the changelog resides * Optimization work + * Removed O(n^2) in cli expand/completion code * Improved performance of validation of (large) lists * A scaling of [large lists](doc/scaling) report is added * New xmldb_get1() returning actual cache - not a copy. This has lead to some householding instead of just deleting the copy diff --git a/apps/cli/cli_show.c b/apps/cli/cli_show.c index a881134b..00ac5d3e 100644 --- a/apps/cli/cli_show.c +++ b/apps/cli/cli_show.c @@ -108,8 +108,7 @@ expand_dbvar(void *h, cxobj *x; char *bodystr; int i; - int j; - int k; + char *bodystr0 = NULL; /* previous */ cg_var *cv; yang_stmt *yspec; cxobj *xtop = NULL; /* xpath root */ @@ -153,9 +152,8 @@ expand_dbvar(void *h, goto done; if (api_path_fmt2api_path(api_path_fmt, cvv, &api_path) < 0) goto done; - - /* XXX read whole configuration, why not send xpath? */ - if (clicon_rpc_get_config(h, dbstr, "/", &xt) < 0) + /* Get configuration */ + if (clicon_rpc_get_config(h, dbstr, xpath, &xt) < 0) goto done; if ((xerr = xpath_first(xt, "/rpc-error")) != NULL){ clicon_rpc_generate_error("Get configuration", xerr); @@ -200,45 +198,20 @@ expand_dbvar(void *h, goto done; } } - /* One round to detect duplicates - */ - j = 0; if (xpath_vec(xcur, "%s", &xvec, &xlen, xpathcur) < 0) goto done; + bodystr0 = NULL; /* Assume sorted XML where duplicates are adjacent */ for (i = 0; i < xlen; i++) { - char *str; x = xvec[i]; if (xml_type(x) == CX_BODY) bodystr = xml_value(x); else bodystr = xml_body(x); - if (bodystr == NULL){ + if (bodystr == NULL) continue; /* no body, cornercase */ - } - /* detect duplicates */ - for (k=0; k