From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44205) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VP1m1-0007n3-9Z for Qemu-devel@nongnu.org; Wed, 25 Sep 2013 22:57:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VP1lw-00053g-8x for Qemu-devel@nongnu.org; Wed, 25 Sep 2013 22:57:49 -0400 Received: from mx1.redhat.com ([209.132.183.28]:39025) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VP1lw-00053S-0j for Qemu-devel@nongnu.org; Wed, 25 Sep 2013 22:57:44 -0400 Message-ID: <5243A2A3.2000502@redhat.com> Date: Wed, 25 Sep 2013 20:57:39 -0600 From: Eric Blake MIME-Version: 1.0 References: <1380160599-15659-1-git-send-email-wudxw@linux.vnet.ibm.com> In-Reply-To: <1380160599-15659-1-git-send-email-wudxw@linux.vnet.ibm.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="7d0qmVGjDmuNMHCXp1O4cmSKvxwDX9g8c" Subject: Re: [Qemu-devel] [PATCH] Add interface to traverse the qmp command list by QmpCommand List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Mark Wu Cc: Michael Roth , Qemu-devel@nongnu.org, Luiz Capitulino This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --7d0qmVGjDmuNMHCXp1O4cmSKvxwDX9g8c Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On 09/25/2013 07:56 PM, Mark Wu wrote: > In the original code, qmp_get_command_list is used to construct > a list of all commands' name. To get the information of all qga > commands, it traverses the name list and search the command info > with its name. So it can cause O(n^2) in the number of commands. >=20 > This patch adds an interface to traverse the qmp command list by > QmpCommand to replace qmp_get_command_list. It can decrease the > complexity from O(n) to O(n^2) from O(n^2) to O(n) >=20 > Signed-off-by: Mark Wu > --- > include/qapi/qmp/dispatch.h | 3 +- > qapi/qmp-registry.c | 28 ++----------------- > qga/commands.c | 39 ++++++++++---------------- > qga/main.c | 68 +++++++++++++++++--------------------= -------- > 4 files changed, 45 insertions(+), 93 deletions(-) >=20 > =20 > -bool qmp_command_is_enabled(const char *name) I think one of Michael's suggestions was that you may still want qmp_command_is_enabled, but with a new signature: bool qmp_command_is_enabled(const QmpCommand *cmd) { return cmd->enabled; } > -struct GuestAgentInfo *qmp_guest_info(Error **err) > +static void qmp_command_info(QmpCommand *cmd, void *opaque) > { > - GuestAgentInfo *info =3D g_malloc0(sizeof(GuestAgentInfo)); > + GuestAgentInfo *info =3D (GuestAgentInfo *)opaque;=20 This is C, not C++. The cast is not necessary. > - cmd_info->enabled =3D qmp_command_is_enabled(cmd_info->name); > =20 > - cmd_info_list =3D g_malloc0(sizeof(GuestAgentCommandInfoList))= ; > - cmd_info_list->value =3D cmd_info; > - cmd_info_list->next =3D info->supported_commands; > - info->supported_commands =3D cmd_info_list; > + cmd_info =3D g_malloc0(sizeof(GuestAgentCommandInfo)); > + cmd_info->name =3D g_strdup(cmd->name); > + cmd_info->enabled =3D cmd->enabled; I guess it all depends on whether we want QmpCommand to be an opaque type outside of a single file. But I don't have a strong argument for making it opaque, and your approach works if we don't mind exposing the details of QmpCommand across multiple files. So I can live with your patch as-is. > +static void ga_enable_non_blacklisted(QmpCommand *cmd, void *opaque) > { > + GList *blacklist =3D (GList *)opaque; Again, the cast is not necessary. Overall, I like the patch. Just a few tweaks suggested, but I can live with you adding: Reviewed-by: Eric Blake --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --7d0qmVGjDmuNMHCXp1O4cmSKvxwDX9g8c Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.14 (GNU/Linux) Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBCAAGBQJSQ6KkAAoJEKeha0olJ0NqrG8H/iAWbPYjLdNHf4YYDBsKGHSF OxRcz+bsaWfzhDi3xtsYUkxjTZQ5MbgATdTM+d0behcYj8w9kc+24HsMQD0WfEEW jLWPscQMW5erC395ZQbfTEAPrYiSodnmh4ozPH2x2GF3vovwhubIGTMBMpRLCe0Q ASfEli7T7kB5xNZnAx1GbWfHL8Vb841t0eTKoBMznPl3EC8dKO/RNNNhXwUN1QHp bFokEZLYFStMRp5kZj5ZbJv0Uzbu763qhDsDazpVmnWUXjDiWyUGbY5Od+WGpgPi euAbsSYfm7yZbX6XgXORxakm7RxFvRZTakqUx9ZPv2uaU/AAbHUtBBHQOs7fJQc= =yB1k -----END PGP SIGNATURE----- --7d0qmVGjDmuNMHCXp1O4cmSKvxwDX9g8c--