[RFC PATCH v1 16/17] vmstate: Declare variables at the top

Fabiano Rosas posted 17 patches 1 week, 2 days ago
[RFC PATCH v1 16/17] vmstate: Declare variables at the top
Posted by Fabiano Rosas 1 week, 2 days ago
Move the variables declaration at the top so we can reduce the number
of lines in the function by grouping some declarations.

Signed-off-by: Fabiano Rosas <farosas@suse.de>
---
 migration/vmstate.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/migration/vmstate.c b/migration/vmstate.c
index 1862198c70..054e642ec9 100644
--- a/migration/vmstate.c
+++ b/migration/vmstate.c
@@ -292,6 +292,8 @@ bool vmstate_load_vmsd(QEMUFile *f, const VMStateDescription *vmsd,
 
     while (field->name) {
         bool exists;
+        void *head;
+        int i, n_elems, size;
 
         ok = vmstate_field_exists(vmsd, field, opaque, version_id, &exists,
                                   errp);
@@ -305,9 +307,8 @@ bool vmstate_load_vmsd(QEMUFile *f, const VMStateDescription *vmsd,
             field++;
             continue;
         } else {
-            void *head;
-            int i, n_elems = vmstate_n_elems(opaque, field);
-            int size = vmstate_size(opaque, field);
+            n_elems = vmstate_n_elems(opaque, field);
+            size = vmstate_size(opaque, field);
 
             head = vmstate_first(opaque, field, size, n_elems,
                                  !(field->flags & VMS_ARRAY_OF_POINTER));
@@ -649,7 +650,9 @@ static bool vmstate_save_vmsd_v(QEMUFile *f, const VMStateDescription *vmsd,
     }
 
     while (field->name) {
-        bool exists;
+        bool exists, is_null_prev = false, use_vmdesc = true;
+        void *head;
+        int i, n_elems, size;
 
         ok = vmstate_field_exists(vmsd, field, opaque, version_id, &exists,
                                   errp);
@@ -661,11 +664,8 @@ static bool vmstate_save_vmsd_v(QEMUFile *f, const VMStateDescription *vmsd,
             field++;
             continue;
         } else {
-            void *head;
-            int i, n_elems = vmstate_n_elems(opaque, field);
-            int size = vmstate_size(opaque, field);
-            bool is_null_prev = false;
-            bool use_vmdesc = true;
+            n_elems = vmstate_n_elems(opaque, field);
+            size = vmstate_size(opaque, field);
 
             trace_vmstate_save_state_loop(vmsd->name, field->name, n_elems);
             head = vmstate_first(opaque, field, size, n_elems, false);
-- 
2.51.0