]> git.proxmox.com Git - qemu.git/commitdiff
qom: add a fast path to object_class_dynamic_cast
authorPaolo Bonzini <pbonzini@redhat.com>
Fri, 10 May 2013 12:16:37 +0000 (14:16 +0200)
committerAnthony Liguori <aliguori@us.ibm.com>
Mon, 13 May 2013 14:52:06 +0000 (09:52 -0500)
For leaf classes, in many cases the callbacks will simply downcast
the object back to the original class.  Add this fast path to
object_class_dynamic_cast, object_dynamic_cast will inherit it.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Message-id: 1368188203-3407-4-git-send-email-pbonzini@redhat.com
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
qom/object.c

index 35f4694987d2850d7bd6b402ad0f2779339bb5c6..0aa0c07d70e5639127a4d89571e67531fa23248f 100644 (file)
@@ -457,7 +457,12 @@ ObjectClass *object_class_dynamic_cast(ObjectClass *class,
         return NULL;
     }
 
+    /* A simple fast path that can trigger a lot for leaf classes.  */
     type = class->type;
+    if (type->name == typename) {
+        return class;
+    }
+
     target_type = type_get_by_name(typename);
     if (!target_type) {
         /* target class type unknown, so fail the cast */