From 3556c233d931ad5ffa46a35cb25cfc057732ebb8 Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Fri, 10 May 2013 14:16:40 +0200 Subject: qom: allow turning cast debugging off Cast debugging can have a substantial cost (20% or more). Instead of adding special-cased "fast casts" in the hot paths, we can just disable it in releases. The tracing facilities we just added make it easier to analyze those problems that cast debugging would reveal. Signed-off-by: Paolo Bonzini Message-id: 1368188203-3407-7-git-send-email-pbonzini@redhat.com Signed-off-by: Anthony Liguori --- qom/object.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'qom') diff --git a/qom/object.c b/qom/object.c index 1b9c5ce4f8..f5f416bc81 100644 --- a/qom/object.c +++ b/qom/object.c @@ -435,12 +435,11 @@ Object *object_dynamic_cast(Object *obj, const char *typename) Object *object_dynamic_cast_assert(Object *obj, const char *typename, const char *file, int line, const char *func) { - Object *inst; - trace_object_dynamic_cast_assert(obj ? obj->class->type->name : "(null)", typename, file, line, func); - inst = object_dynamic_cast(obj, typename); +#ifdef CONFIG_QOM_CAST_DEBUG + Object *inst = object_dynamic_cast(obj, typename); if (!inst && obj) { fprintf(stderr, "%s:%d:%s: Object %p is not an instance of type %s\n", @@ -448,7 +447,9 @@ Object *object_dynamic_cast_assert(Object *obj, const char *typename, abort(); } - return inst; + assert(obj == inst); +#endif + return obj; } ObjectClass *object_class_dynamic_cast(ObjectClass *class, @@ -509,6 +510,12 @@ ObjectClass *object_class_dynamic_cast_assert(ObjectClass *class, trace_object_class_dynamic_cast_assert(class ? class->type->name : "(null)", typename, file, line, func); +#ifndef CONFIG_QOM_CAST_DEBUG + if (!class->interfaces) { + return class; + } +#endif + ret = object_class_dynamic_cast(class, typename); if (!ret && class) { fprintf(stderr, "%s:%d:%s: Object %p is not an instance of type %s\n", -- cgit v1.2.1