From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:49685) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SYtjb-00045I-AF for qemu-devel@nongnu.org; Mon, 28 May 2012 02:47:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SYtjY-00018R-K4 for qemu-devel@nongnu.org; Mon, 28 May 2012 02:47:18 -0400 Received: from mx1.redhat.com ([209.132.183.28]:29648) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SYtjY-00018E-Bq for qemu-devel@nongnu.org; Mon, 28 May 2012 02:47:16 -0400 Message-ID: <4FC31F69.6040601@redhat.com> Date: Mon, 28 May 2012 08:47:05 +0200 From: Paolo Bonzini MIME-Version: 1.0 References: <1338074350-20574-1-git-send-email-afaerber@suse.de> In-Reply-To: <1338074350-20574-1-git-send-email-afaerber@suse.de> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH qom-next] qom: Introduce object_property_is_{child, link}() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: =?UTF-8?B?QW5kcmVhcyBGw6RyYmVy?= Cc: Alexander Barabash , qemu-devel@nongnu.org, Anthony Liguori Il 27/05/2012 01:19, Andreas F=C3=A4rber ha scritto: > Avoids hardcoding partial string comparisons. >=20 > Signed-off-by: Alexander Barabash > Signed-off-by: Andreas F=C3=A4rber > --- > qom/object.c | 22 ++++++++++++++++------ > 1 files changed, 16 insertions(+), 6 deletions(-) >=20 > diff --git a/qom/object.c b/qom/object.c > index 173835b..00bb3b0 100644 > --- a/qom/object.c > +++ b/qom/object.c > @@ -305,6 +305,16 @@ void object_initialize(void *data, const char *typ= ename) > object_initialize_with_type(data, type); > } > =20 > +static inline bool object_property_is_child(ObjectProperty *prop) > +{ > + return strstart(prop->type, "child<", NULL); > +} > + > +static inline bool object_property_is_link(ObjectProperty *prop) > +{ > + return strstart(prop->type, "link<", NULL); > +} > + > static void object_property_del_all(Object *obj) > { > while (!QTAILQ_EMPTY(&obj->properties)) { > @@ -327,7 +337,7 @@ static void object_property_del_child(Object *obj, = Object *child, Error **errp) > ObjectProperty *prop; > =20 > QTAILQ_FOREACH(prop, &obj->properties, node) { > - if (strstart(prop->type, "child<", NULL) && prop->opaque =3D=3D= child) { > + if (object_property_is_child(prop) && prop->opaque =3D=3D chil= d) { > object_property_del(obj, prop->name, errp); > break; > } > @@ -600,7 +610,7 @@ int object_child_foreach(Object *obj, int (*fn)(Obj= ect *child, void *opaque), > int ret =3D 0; > =20 > QTAILQ_FOREACH(prop, &obj->properties, node) { > - if (strstart(prop->type, "child<", NULL)) { > + if (object_property_is_child(prop)) { > ret =3D fn(prop->opaque, opaque); > if (ret !=3D 0) { > break; > @@ -1022,7 +1032,7 @@ gchar *object_get_canonical_path(Object *obj) > g_assert(obj->parent !=3D NULL); > =20 > QTAILQ_FOREACH(prop, &obj->parent->properties, node) { > - if (!strstart(prop->type, "child<", NULL)) { > + if (!object_property_is_child(prop)) { > continue; > } > =20 > @@ -1056,9 +1066,9 @@ Object *object_resolve_path_component(Object *par= ent, gchar *part) > return NULL; > } > =20 > - if (strstart(prop->type, "link<", NULL)) { > + if (object_property_is_link(prop)) { > return *(Object **)prop->opaque; > - } else if (strstart(prop->type, "child<", NULL)) { > + } else if (object_property_is_child(prop)) { > return prop->opaque; > } else { > return NULL; > @@ -1101,7 +1111,7 @@ static Object *object_resolve_partial_path(Object= *parent, > QTAILQ_FOREACH(prop, &parent->properties, node) { > Object *found; > =20 > - if (!strstart(prop->type, "child<", NULL)) { > + if (!object_property_is_child(prop)) { > continue; > } > =20 Reviewed-by: Paolo Bonzini Paolo