[PATCH 5/7] qemuMigrationCapsToJSON: Refactor variable cleanup
Ján Tomko
jtomko at redhat.com
Mon Aug 24 13:27:40 UTC 2020
On a Monday in 2020, Peter Krempa wrote:
>Use automatic memory allocation and move variables into correct scope to
>simplify the code and remove the need for a 'error:' label.
>
>Signed-off-by: Peter Krempa <pkrempa at redhat.com>
>---
> src/qemu/qemu_migration_params.c | 24 +++++++-----------------
> 1 file changed, 7 insertions(+), 17 deletions(-)
>
>diff --git a/src/qemu/qemu_migration_params.c b/src/qemu/qemu_migration_params.c
>index c22362735a..9b6601367a 100644
>--- a/src/qemu/qemu_migration_params.c
>+++ b/src/qemu/qemu_migration_params.c
>@@ -759,14 +759,12 @@ virJSONValuePtr
> qemuMigrationCapsToJSON(virBitmapPtr caps,
> virBitmapPtr states)
> {
>- virJSONValuePtr json = NULL;
>- virJSONValuePtr cap = NULL;
>+ g_autoptr(virJSONValue) json = virJSONValueNewArray();
> qemuMigrationCapability bit;
>- const char *name;
>-
>- json = virJSONValueNewArray();
>
> for (bit = 0; bit < QEMU_MIGRATION_CAP_LAST; bit++) {
>+ g_autoptr(virJSONValue) cap = virJSONValueNewObject();
>+ const char *name = qemuMigrationCapabilityTypeToString(bit);
I don't like allocating the JSON object and converting the string
if we might 'continue' without using it, but I doubt it will have a
measurable effect.
> bool supported = false;
> bool state = false;
>
Reviewed-by: Ján Tomko <jtomko at redhat.com>
Jano
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20200824/888c9d38/attachment-0001.sig>
More information about the libvir-list
mailing list