From nobody Wed Nov 27 06:42:30 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1699885218; cv=none; d=zohomail.com; s=zohoarc; b=ZlZ0CYnp8s5y81ZeWJkn13mxZkdMk9717rXMnSDeJrMqiRBlsdaHOY4EoMwx2AFnC1sLdEO3Q8nd478cZeZAGen6Rs1eYsiMnAOyWVD94eaSsxWDVXdJ3e6wrNefLQvfG9k0MPKaKHHPU+gCWkjil/x5NhReI0YaFPRdiUv8t2U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1699885218; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:Sender:Subject:Subject:To:To:Message-Id; bh=p0rgS/TIT9CSiAz+Hwn7Fwmra9MIBJIurfqlp4+vYKk=; b=HCiN3ZuZmaJ2aGq8YszYgi8tTK9I84SFlHNwfrFDiiDd5lQKvUk5u36wNjErg7uSxxolzcGCqm1qOEwLi/RR28qlksjgzy5IQFanp5d6DygFGM4fR65hTD1CGTLDYAduyFqmymeLgmJTOqGwfQijh0n8OIpkZfQIJxwr4kbyW8k= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1699885218549476.8056273377364; Mon, 13 Nov 2023 06:20:18 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r2XnM-00023X-VZ; Mon, 13 Nov 2023 09:20:09 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r2XnK-00022t-Tg for qemu-devel@nongnu.org; Mon, 13 Nov 2023 09:20:06 -0500 Received: from mx20.baidu.com ([111.202.115.85] helo=baidu.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r2XnG-0005vf-R2 for qemu-devel@nongnu.org; Mon, 13 Nov 2023 09:20:06 -0500 To: Markus Armbruster , Juan Quintela , Konstantin Kostiuk , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , "Dr. David Alan Gilbert" CC: , Gao Shiyuan Subject: [PATCH] util/qemu-config: Remove unnecessary traversal Date: Mon, 13 Nov 2023 22:19:36 +0800 Message-ID: <20231113141936.30567-1-gaoshiyuan@baidu.com> X-Mailer: git-send-email 2.37.1 (Apple Git-137.1) MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [172.31.63.8] X-ClientProxiedBy: BJHW-Mail-Ex08.internal.baidu.com (10.127.64.18) To bjkjy-mail-ex26.internal.baidu.com (172.31.50.42) X-FEAS-Client-IP: 172.31.51.13 X-FE-Policy-ID: 15:10:21:SYSTEM Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=111.202.115.85; envelope-from=gaoshiyuan@baidu.com; helo=baidu.com X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-to: Shiyuan Gao From: Shiyuan Gao via Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1699885220773100003 Content-Type: text/plain; charset="utf-8" From: Gao Shiyuan No remove QemuOptsList from *_config_groups, so no need to traverse from the beginning every time. No functional changes. Signed-off-by: Gao Shiyuan --- include/qemu/config-file.h | 3 +++ util/qemu-config.c | 18 ++++++++---------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/include/qemu/config-file.h b/include/qemu/config-file.h index b82a778123..223ef7bc8f 100644 --- a/include/qemu/config-file.h +++ b/include/qemu/config-file.h @@ -1,6 +1,9 @@ #ifndef QEMU_CONFIG_FILE_H #define QEMU_CONFIG_FILE_H =20 +#define MAX_VM_CONFIG_GROUPS 48 +#define MAX_DRIVE_CONFIG_GROUPS 5 + typedef void QEMUConfigCB(const char *group, QDict *qdict, void *opaque, E= rror **errp); =20 void qemu_load_module_for_opts(const char *group); diff --git a/util/qemu-config.c b/util/qemu-config.c index 42076efe1e..d7bab2047f 100644 --- a/util/qemu-config.c +++ b/util/qemu-config.c @@ -9,8 +9,8 @@ #include "qemu/config-file.h" #include "hw/boards.h" =20 -static QemuOptsList *vm_config_groups[48]; -static QemuOptsList *drive_config_groups[5]; +static QemuOptsList *vm_config_groups[MAX_VM_CONFIG_GROUPS]; +static QemuOptsList *drive_config_groups[MAX_DRIVE_CONFIG_GROUPS]; =20 static QemuOptsList *find_list(QemuOptsList **lists, const char *group, Error **errp) @@ -260,11 +260,10 @@ QemuOptsList *qemu_find_opts_err(const char *group, E= rror **errp) =20 void qemu_add_drive_opts(QemuOptsList *list) { - int entries, i; + static int i; + static int entries =3D MAX_DRIVE_CONFIG_GROUPS - 1; /* keep list NULL = terminated */ =20 - entries =3D ARRAY_SIZE(drive_config_groups); - entries--; /* keep list NULL terminated */ - for (i =3D 0; i < entries; i++) { + for (; i < entries; i++) { if (drive_config_groups[i] =3D=3D NULL) { drive_config_groups[i] =3D list; return; @@ -276,11 +275,10 @@ void qemu_add_drive_opts(QemuOptsList *list) =20 void qemu_add_opts(QemuOptsList *list) { - int entries, i; + static int i; + static int entries =3D MAX_VM_CONFIG_GROUPS - 1; /* keep list NULL ter= minated */ =20 - entries =3D ARRAY_SIZE(vm_config_groups); - entries--; /* keep list NULL terminated */ - for (i =3D 0; i < entries; i++) { + for (; i < entries; i++) { if (vm_config_groups[i] =3D=3D NULL) { vm_config_groups[i] =3D list; return; --=20 2.27.0