From nobody Thu May 2 18:23:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=163.com Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1630485981787413.54678826299767; Wed, 1 Sep 2021 01:46:21 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-210-bG4rjyF2P5GhERZySEWXjw-1; Wed, 01 Sep 2021 04:46:18 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id CE5BA800FF3; Wed, 1 Sep 2021 08:46:13 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id AF1106A8EE; Wed, 1 Sep 2021 08:46:13 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 5A4C31809C98; Wed, 1 Sep 2021 08:46:13 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 1813KNOR015713 for ; Tue, 31 Aug 2021 23:20:23 -0400 Received: by smtp.corp.redhat.com (Postfix) id 37609D7B32; Wed, 1 Sep 2021 03:20:23 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast03.extmail.prod.ext.rdu2.redhat.com [10.11.55.19]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 317B8D7B2E for ; Wed, 1 Sep 2021 03:20:19 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-2.mimecast.com [207.211.31.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D9C9A811E7F for ; Wed, 1 Sep 2021 03:20:19 +0000 (UTC) Received: from m12-13.163.com (m12-13.163.com [220.181.12.13]) by relay.mimecast.com with ESMTP id us-mta-555-dEn04Z7aOKaqukojducs7g-1; Tue, 31 Aug 2021 23:20:15 -0400 Received: from localhost.localdomain (unknown [182.42.116.25]) by smtp9 (Coremail) with SMTP id DcCowAAnh5fg7S5hsonbBg--.32345S2; Wed, 01 Sep 2021 11:05:05 +0800 (CST) X-MC-Unique: bG4rjyF2P5GhERZySEWXjw-1 X-MC-Unique: dEn04Z7aOKaqukojducs7g-1 From: renlei1998@163.com To: libvir-list@redhat.com Subject: [PATCH] qemu: remove unnecessary strlen for LINE_ENDING Date: Wed, 1 Sep 2021 11:04:56 +0800 Message-Id: <20210901030456.54635-1-renlei1998@163.com> MIME-Version: 1.0 X-CM-TRANSID: DcCowAAnh5fg7S5hsonbBg--.32345S2 X-Coremail-Antispam: 1Uf129KBjvJXoW7Ar48CFWfKFyrJFWxuw4rKrg_yoW8Aw1kpw srZas8KrZYqwnrXF4IkrW7uFnxGr12vryDCr40yan2qF1rJ3W0qr1xAryqqFZ8XrZ5Aa1j 9rySkryj9Fs0q3DanT9S1TB71UUUUUDqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07jOrcfUUUUU= X-Originating-IP: [182.42.116.25] X-CM-SenderInfo: xuhqzvjlrzmmi6rwjhhfrp/1tbiEAEBIF8YHKk0XgAAso X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-loop: libvir-list@redhat.com X-Mailman-Approved-At: Wed, 01 Sep 2021 04:46:11 -0400 Cc: Ren Lei X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1630485983662100001 Content-Type: text/plain; charset="utf-8" From: Ren Lei the length of LINE_ENDING is static, it's a waste to call strlen every time. Signed-off-by: Ren Lei --- 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"); =20 #define LINE_ENDING "\n" +#define LINE_ENDING_LENGTH 1 =20 #define DEBUG_IO 0 #define DEBUG_RAW_IO 0 @@ -341,11 +342,11 @@ static int qemuAgentIOProcessData(qemuAgent *agent, =20 if (nl) { int got =3D nl - (data + used); - for (i =3D 0; i < strlen(LINE_ENDING); i++) + for (i =3D 0; i < LINE_ENDING_LENGTH; i++) data[used + got + i] =3D '\0'; if (qemuAgentIOProcessLine(agent, data + used, msg) < 0) return -1; - used +=3D got + strlen(LINE_ENDING); + used +=3D 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]" =20 #define LINE_ENDING "\r\n" +#define LINE_ENDING_LENGTH 2 =20 VIR_ENUM_IMPL(qemuMonitorJob, QEMU_MONITOR_JOB_TYPE_LAST, @@ -271,7 +272,7 @@ int qemuMonitorJSONIOProcess(qemuMonitor *mon, int got =3D nl - (data + used); char *line; line =3D g_strndup(data + used, got); - used +=3D got + strlen(LINE_ENDING); + used +=3D got + LINE_ENDING_LENGTH; line[got] =3D '\0'; /* kill \n */ if (qemuMonitorJSONIOProcessLine(mon, line, msg) < 0) { VIR_FREE(line); --=20 2.27.0