Received: from eggs.gnu.org ([208.118.235.92]:45744) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SYQGb-0005w7-MK for qemu-devel@nongnu.org; Sat, 26 May 2012 19:19:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SYQGZ-0005Ky-NO for qemu-devel@nongnu.org; Sat, 26 May 2012 19:19:25 -0400 Received: from cantor2.suse.de ([195.135.220.15]:56016 helo=mx2.suse.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SYQGZ-0005Kg-Dy for qemu-devel@nongnu.org; Sat, 26 May 2012 19:19:23 -0400 From: =?UTF-8?q?Andreas=20F=C3=A4rber?= Date: Sun, 27 May 2012 01:19:10 +0200 Message-Id: <1338074350-20574-1-git-send-email-afaerber@suse.de> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [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: qemu-devel@nongnu.org Cc: Paolo Bonzini , Alexander Barabash , =?UTF-8?q?Andreas=20F=C3=A4rber?= , Anthony Liguori Avoids hardcoding partial string comparisons. Signed-off-by: Alexander Barabash Signed-off-by: Andreas F=C3=A4rber --- qom/object.c | 22 ++++++++++++++++------ 1 files changed, 16 insertions(+), 6 deletions(-) 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 *typen= ame) 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, Ob= ject *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 child)= { object_property_del(obj, prop->name, errp); break; } @@ -600,7 +610,7 @@ int object_child_foreach(Object *obj, int (*fn)(Objec= t *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 *paren= t, 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 --=20 1.7.7