[PATCH] qemu: remove unnecessary strlen for LINE_ENDING

renlei1998 at 163.com renlei1998 at 163.com
Wed Sep 1 03:04:56 UTC 2021


From: Ren Lei <ren.lei4 at zte.com.cn>

the length of LINE_ENDING is static, it's a waste to call
strlen every time.

Signed-off-by: Ren Lei <ren.lei4 at zte.com.cn>
---
 src/qemu/qemu_agent.c        | 5 +++--
 src/qemu/qemu_monitor_json.c | 3 ++-
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/src/qemu/qemu_agent.c b/src/qemu/qemu_agent.c
index 5f421be6f6..3a453b4c58 100644
--- a/src/qemu/qemu_agent.c
+++ b/src/qemu/qemu_agent.c
@@ -47,6 +47,7 @@
 VIR_LOG_INIT("qemu.qemu_agent");
 
 #define LINE_ENDING "\n"
+#define LINE_ENDING_LENGTH 1
 
 #define DEBUG_IO 0
 #define DEBUG_RAW_IO 0
@@ -341,11 +342,11 @@ static int qemuAgentIOProcessData(qemuAgent *agent,
 
         if (nl) {
             int got = nl - (data + used);
-            for (i = 0; i < strlen(LINE_ENDING); i++)
+            for (i = 0; i < LINE_ENDING_LENGTH; i++)
                 data[used + got + i] = '\0';
             if (qemuAgentIOProcessLine(agent, data + used, msg) < 0)
                 return -1;
-            used += got + strlen(LINE_ENDING);
+            used += got + LINE_ENDING_LENGTH;
         } else {
             break;
         }
diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index 8d3c4031a6..8b77b3cdaa 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -51,6 +51,7 @@ VIR_LOG_INIT("qemu.qemu_monitor_json");
 #define QOM_CPU_PATH  "/machine/unattached/device[0]"
 
 #define LINE_ENDING "\r\n"
+#define LINE_ENDING_LENGTH 2
 
 VIR_ENUM_IMPL(qemuMonitorJob,
               QEMU_MONITOR_JOB_TYPE_LAST,
@@ -271,7 +272,7 @@ int qemuMonitorJSONIOProcess(qemuMonitor *mon,
             int got = nl - (data + used);
             char *line;
             line = g_strndup(data + used, got);
-            used += got + strlen(LINE_ENDING);
+            used += got + LINE_ENDING_LENGTH;
             line[got] = '\0'; /* kill \n */
             if (qemuMonitorJSONIOProcessLine(mon, line, msg) < 0) {
                 VIR_FREE(line);
-- 
2.27.0





More information about the libvir-list mailing list