From patchwork Mon Jun 18 13:58:54 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Andreas_F=C3=A4rber?= X-Patchwork-Id: 165489 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 39978B70B1 for ; Tue, 19 Jun 2012 01:30:19 +1000 (EST) Received: from localhost ([::1]:39246 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SgcW4-0003xS-3n for incoming@patchwork.ozlabs.org; Mon, 18 Jun 2012 10:01:16 -0400 Received: from eggs.gnu.org ([208.118.235.92]:37915) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SgcUu-0001eE-5q for qemu-devel@nongnu.org; Mon, 18 Jun 2012 10:00:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SgcUR-0003VK-Tl for qemu-devel@nongnu.org; Mon, 18 Jun 2012 10:00:03 -0400 Received: from cantor2.suse.de ([195.135.220.15]:53219 helo=mx2.suse.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SgcUR-0003Uy-KS for qemu-devel@nongnu.org; Mon, 18 Jun 2012 09:59:35 -0400 Received: from relay1.suse.de (unknown [195.135.220.254]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx2.suse.de (Postfix) with ESMTP id 1BFE5A3EFF; Mon, 18 Jun 2012 15:59:34 +0200 (CEST) From: =?UTF-8?q?Andreas=20F=C3=A4rber?= To: qemu-devel@nongnu.org Date: Mon, 18 Jun 2012 15:58:54 +0200 Message-Id: <1340027954-19045-3-git-send-email-afaerber@suse.de> X-Mailer: git-send-email 1.7.7 In-Reply-To: <1340027954-19045-1-git-send-email-afaerber@suse.de> References: <1340027954-19045-1-git-send-email-afaerber@suse.de> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4-2.6 X-Received-From: 195.135.220.15 Cc: Alexander Barabash , =?UTF-8?q?Andreas=20F=C3=A4rber?= , Anthony Liguori Subject: [Qemu-devel] [PATCH 02/22] qom: Introduce object_property_is_{child, link}() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Avoids hardcoding partial string comparisons. Signed-off-by: Alexander Barabash Signed-off-by: Andreas Färber Reviewed-by: Paolo Bonzini --- qom/object.c | 20 +++++++++++++++----- 1 files changed, 15 insertions(+), 5 deletions(-) diff --git a/qom/object.c b/qom/object.c index 9582230..105c649 100644 --- a/qom/object.c +++ b/qom/object.c @@ -296,6 +296,16 @@ void object_initialize(void *data, const char *typename) object_initialize_with_type(data, type); } +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)) { @@ -318,7 +328,7 @@ static void object_property_del_child(Object *obj, Object *child, Error **errp) ObjectProperty *prop; QTAILQ_FOREACH(prop, &obj->properties, node) { - if (strstart(prop->type, "child<", NULL) && prop->opaque == child) { + if (object_property_is_child(prop) && prop->opaque == child) { object_property_del(obj, prop->name, errp); break; } @@ -1008,7 +1018,7 @@ gchar *object_get_canonical_path(Object *obj) g_assert(obj->parent != NULL); QTAILQ_FOREACH(prop, &obj->parent->properties, node) { - if (!strstart(prop->type, "child<", NULL)) { + if (!object_property_is_child(prop)) { continue; } @@ -1042,9 +1052,9 @@ Object *object_resolve_path_component(Object *parent, gchar *part) return NULL; } - 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; @@ -1087,7 +1097,7 @@ static Object *object_resolve_partial_path(Object *parent, QTAILQ_FOREACH(prop, &parent->properties, node) { Object *found; - if (!strstart(prop->type, "child<", NULL)) { + if (!object_property_is_child(prop)) { continue; }