From nobody Mon Feb 9 00:27:06 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1516893838539196.30036579110026; Thu, 25 Jan 2018 07:23:58 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 63F3355892; Thu, 25 Jan 2018 15:23:57 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1E7D3537B3; Thu, 25 Jan 2018 15:23:57 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 9725318033DD; Thu, 25 Jan 2018 15:23:56 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w0PFNtcm008950 for ; Thu, 25 Jan 2018 10:23:55 -0500 Received: by smtp.corp.redhat.com (Postfix) id 6F6056090C; Thu, 25 Jan 2018 15:23:55 +0000 (UTC) Received: from beluga.usersys.redhat.com (unknown [10.43.2.166]) by smtp.corp.redhat.com (Postfix) with ESMTP id 64B836A054; Thu, 25 Jan 2018 15:23:36 +0000 (UTC) From: Erik Skultety To: libvir-list@redhat.com Date: Thu, 25 Jan 2018 16:22:55 +0100 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Cc: Erik Skultety Subject: [libvirt] [PATCH 1/2] vsh: Drop redundant definition searches from vshCmd{def, Grp}Help X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Thu, 25 Jan 2018 15:23:57 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" These helpers are called from a single place only - cmdHelp wrapper and just before the wrapper invokes the helpers, it performs the search, either for command group or for the command itself, except the result is discarded and the helper therefore needs to do it again. Drop this inefficient handling and pass the @def structure rather than a name, thus preventing the helper from needing to perform the search again. Signed-off-by: Erik Skultety --- tools/vsh.c | 43 +++++++++++++++---------------------------- tools/vsh.h | 4 ++-- 2 files changed, 17 insertions(+), 30 deletions(-) diff --git a/tools/vsh.c b/tools/vsh.c index 058df7ef6..761d2ec3a 100644 --- a/tools/vsh.c +++ b/tools/vsh.c @@ -629,44 +629,32 @@ vshCmdGrpSearch(const char *grpname) } =20 bool -vshCmdGrpHelp(vshControl *ctl, const char *grpname) +vshCmdGrpHelp(vshControl *ctl, const vshCmdGrp *grp) { - const vshCmdGrp *grp =3D vshCmdGrpSearch(grpname); const vshCmdDef *cmd =3D NULL; =20 - if (!grp) { - vshError(ctl, _("command group '%s' doesn't exist"), grpname); - return false; - } else { - vshPrint(ctl, _(" %s (help keyword '%s'):\n"), grp->name, - grp->keyword); + vshPrint(ctl, _(" %s (help keyword '%s'):\n"), grp->name, + grp->keyword); =20 - for (cmd =3D grp->commands; cmd->name; cmd++) { - if (cmd->flags & VSH_CMD_FLAG_ALIAS) - continue; - vshPrint(ctl, " %-30s %s\n", cmd->name, - _(vshCmddefGetInfo(cmd, "help"))); - } + for (cmd =3D grp->commands; cmd->name; cmd++) { + if (cmd->flags & VSH_CMD_FLAG_ALIAS) + continue; + vshPrint(ctl, " %-30s %s\n", cmd->name, + _(vshCmddefGetInfo(cmd, "help"))); } =20 return true; } =20 bool -vshCmddefHelp(vshControl *ctl, const char *cmdname) +vshCmddefHelp(vshControl *ctl, const vshCmdDef *def) { - const vshCmdDef *def =3D vshCmddefSearch(cmdname); const char *desc =3D NULL; char buf[256]; uint64_t opts_need_arg; uint64_t opts_required; bool shortopt =3D false; /* true if 'arg' works instead of '--opt arg'= */ =20 - if (!def) { - vshError(ctl, _("command '%s' doesn't exist"), cmdname); - return false; - } - if (vshCmddefOptParse(def, &opts_need_arg, &opts_required)) { vshError(ctl, _("internal error: bad options in command: '%s'"), def->name); @@ -3181,12 +3169,11 @@ const vshCmdInfo info_help[] =3D { bool cmdHelp(vshControl *ctl, const vshCmd *cmd) { + const vshCmdDef *def =3D NULL; + const vshCmdGrp *grp =3D NULL; const char *name =3D NULL; =20 if (vshCommandOptStringQuiet(ctl, cmd, "command", &name) <=3D 0) { - const vshCmdGrp *grp; - const vshCmdDef *def; - vshPrint(ctl, "%s", _("Grouped commands:\n\n")); =20 for (grp =3D cmdGroups; grp->name; grp++) { @@ -3206,10 +3193,10 @@ cmdHelp(vshControl *ctl, const vshCmd *cmd) return true; } =20 - if (vshCmddefSearch(name)) { - return vshCmddefHelp(ctl, name); - } else if (vshCmdGrpSearch(name)) { - return vshCmdGrpHelp(ctl, name); + if ((def =3D vshCmddefSearch(name))) { + return vshCmddefHelp(ctl, def); + } else if ((grp =3D vshCmdGrpSearch(name))) { + return vshCmdGrpHelp(ctl, grp); } else { vshError(ctl, _("command or command group '%s' doesn't exist"), na= me); return false; diff --git a/tools/vsh.h b/tools/vsh.h index 6894700d9..694476471 100644 --- a/tools/vsh.h +++ b/tools/vsh.h @@ -257,9 +257,9 @@ void vshCloseLogFile(vshControl *ctl); =20 const char *vshCmddefGetInfo(const vshCmdDef *cmd, const char *info); const vshCmdDef *vshCmddefSearch(const char *cmdname); -bool vshCmddefHelp(vshControl *ctl, const char *name); +bool vshCmddefHelp(vshControl *ctl, const vshCmdDef *def); const vshCmdGrp *vshCmdGrpSearch(const char *grpname); -bool vshCmdGrpHelp(vshControl *ctl, const char *name); +bool vshCmdGrpHelp(vshControl *ctl, const vshCmdGrp *grp); =20 int vshCommandOptInt(vshControl *ctl, const vshCmd *cmd, const char *name, int *value) --=20 2.13.6 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list