qom: add a fast path to object_class_dynamic_cast

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>
master
Paolo Bonzini 2013-05-10 14:16:37 +02:00 committed by Anthony Liguori
parent bf0fda3466
commit 793c96b540
1 changed files with 5 additions and 0 deletions

View 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 */