Re: [PATCH] qemu: remove unnecessary strlen for LINE_ENDING

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 8/31/21 11:04 PM, renlei1998@xxxxxxx wrote:
From: Ren Lei <ren.lei4@xxxxxxxxxx>

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

AFAIK gcc optimizes out calls to strlen of a literal constant string, making this hand-optimization unnecessary.


Signed-off-by: Ren Lei <ren.lei4@xxxxxxxxxx>
---
  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);





[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux