[libvirt] [PATCH 04/10] tests: qemumonitor: Optimize control flow when concatenating replies

Peter Krempa posted 10 patches 6 years, 11 months ago
[libvirt] [PATCH 04/10] tests: qemumonitor: Optimize control flow when concatenating replies
Posted by Peter Krempa 6 years, 11 months ago
The test file can be broken up by newlines and is automatically
concatenated back. Fix the control flow so that the concatenation code
'continues' the loop rather than branching out.

Also add an anotation to the concatenation code.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
---
 tests/qemumonitortestutils.c | 38 ++++++++++++++++++++------------------
 1 file changed, 20 insertions(+), 18 deletions(-)

diff --git a/tests/qemumonitortestutils.c b/tests/qemumonitortestutils.c
index a73272e7b0..98c6ce6187 100644
--- a/tests/qemumonitortestutils.c
+++ b/tests/qemumonitortestutils.c
@@ -1422,30 +1422,32 @@ qemuMonitorTestNewFromFileFull(const char *fileName,
         if (!tmp[1])
             break;

+        /* concatenate block which was broken up for readability */
         if (*(tmp + 1) != '\n') {
             *tmp = ' ';
             tmp++;
-        } else {
-            /* Cut off a single reply. */
-            *(tmp + 1) = '\0';
+            continue;
+        }

-            if (response) {
-                if (qemuMonitorTestFullAddItem(ret, fileName, command,
-                                               response, commandln) < 0)
-                    goto error;
-                command = NULL;
-                response = NULL;
-            }
+        /* Cut off a single reply. */
+        *(tmp + 1) = '\0';

-            /* Move the @tmp and @singleReply. */
-            tmp += 2;
+        if (response) {
+            if (qemuMonitorTestFullAddItem(ret, fileName, command,
+                                           response, commandln) < 0)
+                goto error;
+            command = NULL;
+            response = NULL;
+        }

-            if (!command) {
-                commandln = line;
-                command = tmp;
-            } else {
-                response = tmp;
-            }
+        /* Move the @tmp and @singleReply. */
+        tmp += 2;
+
+        if (!command) {
+            commandln = line;
+            command = tmp;
+        } else {
+            response = tmp;
         }
     }

-- 
2.16.2

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 04/10] tests: qemumonitor: Optimize control flow when concatenating replies
Posted by John Ferlan 6 years, 11 months ago

On 06/04/2018 09:58 AM, Peter Krempa wrote:
> The test file can be broken up by newlines and is automatically
> concatenated back. Fix the control flow so that the concatenation code
> 'continues' the loop rather than branching out.
> 
> Also add an anotation to the concatenation code.
> 
> Signed-off-by: Peter Krempa <pkrempa@redhat.com>
> ---
>  tests/qemumonitortestutils.c | 38 ++++++++++++++++++++------------------
>  1 file changed, 20 insertions(+), 18 deletions(-)
> 

Reviewed-by: John Ferlan <jferlan@redhat.com>

John

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list