From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:34509) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RtaaT-0001L7-JN for qemu-devel@nongnu.org; Sat, 04 Feb 2012 03:03:15 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RtaaR-0005AU-GE for qemu-devel@nongnu.org; Sat, 04 Feb 2012 03:03:09 -0500 Received: from mail-ww0-f53.google.com ([74.125.82.53]:63252) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RtaaR-00059M-6l for qemu-devel@nongnu.org; Sat, 04 Feb 2012 03:03:07 -0500 Received: by wgbdr12 with SMTP id dr12so4470350wgb.10 for ; Sat, 04 Feb 2012 00:03:06 -0800 (PST) Sender: Paolo Bonzini From: Paolo Bonzini Date: Sat, 4 Feb 2012 09:02:34 +0100 Message-Id: <1328342577-25732-5-git-send-email-pbonzini@redhat.com> In-Reply-To: <1328342577-25732-1-git-send-email-pbonzini@redhat.com> References: <1328342577-25732-1-git-send-email-pbonzini@redhat.com> Subject: [Qemu-devel] [PATCH v2 04/27] qom: avoid useless conversions from string to type List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Signed-off-by: Paolo Bonzini --- qom/object.c | 16 +++++++++------- 1 files changed, 9 insertions(+), 7 deletions(-) diff --git a/qom/object.c b/qom/object.c index 4d21f0a..a89e9e3 100644 --- a/qom/object.c +++ b/qom/object.c @@ -368,9 +368,10 @@ void object_delete(Object *obj) g_free(obj); } -static bool object_is_type(Object *obj, const char *typename) +static Type type_interface; + +static bool object_is_type(Object *obj, TypeImpl *target_type) { - TypeImpl *target_type = type_get_by_name(typename); TypeImpl *type = obj->class->type; /* Check if typename is a direct ancestor of type */ @@ -387,10 +388,11 @@ static bool object_is_type(Object *obj, const char *typename) Object *object_dynamic_cast(Object *obj, const char *typename) { + TypeImpl *target_type = type_get_by_name(typename); GSList *i; /* Check if typename is a direct ancestor */ - if (object_is_type(obj, typename)) { + if (object_is_type(obj, target_type)) { return obj; } @@ -404,10 +406,10 @@ Object *object_dynamic_cast(Object *obj, const char *typename) * (run-time) type safety and to speed up tests like this one. If we ever * do that we can revisit the order here. */ - if (object_is_type(obj, TYPE_INTERFACE)) { + if (object_is_type(obj, type_interface)) { assert(!obj->interfaces); obj = INTERFACE(obj)->obj; - if (object_is_type(obj, typename)) { + if (object_is_type(obj, target_type)) { return obj; } } @@ -416,7 +418,7 @@ Object *object_dynamic_cast(Object *obj, const char *typename) for (i = obj->interfaces; i; i = i->next) { Interface *iface = i->data; - if (object_is_type(OBJECT(iface), typename)) { + if (object_is_type(OBJECT(iface), target_type)) { return OBJECT(iface); } } @@ -433,7 +435,7 @@ static void register_interface(void) .abstract = true, }; - type_register_static(&interface_info); + type_interface = type_register_static(&interface_info); } device_init(register_interface); -- 1.7.7.6