Instead of having many if-else statements, each with its own
vshTableRowAppend() call, we can use a simple trick - have an
array of string pointers, set array members in the if bodies and
then call vshTableRowAppend() once.
Signed-off-by: Michal Privoznik <mprivozn(a)redhat.com>
---
tools/virsh-domain-monitor.c | 34 +++++++++++++---------------------
1 file changed, 13 insertions(+), 21 deletions(-)
diff --git a/tools/virsh-domain-monitor.c b/tools/virsh-domain-monitor.c
index 80b6857fad..87efd86a69 100644
--- a/tools/virsh-domain-monitor.c
+++ b/tools/virsh-domain-monitor.c
@@ -1891,6 +1891,8 @@ cmdList(vshControl *ctl, const vshCmd *cmd)
if (optTable) {
const char *domName = virDomainGetName(dom);
const char *stateStr = NULL;
+ g_autofree char *title = NULL;
+ const char *arg[2] = {};
state = virshDomainState(ctl, dom, NULL);
@@ -1906,43 +1908,33 @@ cmdList(vshControl *ctl, const vshCmd *cmd)
}
if (optTitle && !optUUID) {
- g_autofree char *title = NULL;
-
if (!(title = virshGetDomainDescription(ctl, dom, true, 0)))
goto cleanup;
- if (vshTableRowAppend(table, id_buf,
- domName, stateStr,
- title, NULL) < 0)
- goto cleanup;
+
+ arg[0] = title;
} else if (optUUID && !optTitle) {
if (virDomainGetUUIDString(dom, uuid) < 0) {
vshError(ctl, "%s", _("Failed to get domain's
UUID"));
goto cleanup;
}
- if (vshTableRowAppend(table, id_buf,
- domName, stateStr,
- uuid, NULL) < 0)
- goto cleanup;
+
+ arg[0] = uuid;
} else if (optUUID && optTitle) {
- g_autofree char *title = NULL;
-
if (!(title = virshGetDomainDescription(ctl, dom, true, 0)))
goto cleanup;
if (virDomainGetUUIDString(dom, uuid) < 0) {
vshError(ctl, "%s", _("Failed to get domain's
UUID"));
goto cleanup;
}
- if (vshTableRowAppend(table, id_buf,
- domName, stateStr,
- title, uuid, NULL) < 0)
- goto cleanup;
- } else {
- if (vshTableRowAppend(table, id_buf,
- domName, stateStr,
- NULL) < 0)
- goto cleanup;
+
+ arg[0] = title;
+ arg[1] = uuid;
}
+ if (vshTableRowAppend(table, id_buf,
+ domName, stateStr,
+ arg[0], arg[1], NULL) < 0)
+ goto cleanup;
} else {
if (optUUID) {
if (virDomainGetUUIDString(dom, uuid) < 0) {
--
2.44.2