diff mbox

[for-1.5,8/9] qom: simplify object_class_dynamic_cast, part 1

Message ID 1368188203-3407-9-git-send-email-pbonzini@redhat.com
State New
Headers show

Commit Message

Paolo Bonzini May 10, 2013, 12:16 p.m. UTC
Access everything from the class.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 qom/object.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

Comments

Anthony Liguori May 10, 2013, 5:52 p.m. UTC | #1
Paolo Bonzini <pbonzini@redhat.com> writes:

> Access everything from the class.
>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>  qom/object.c | 8 +++-----
>  1 file changed, 3 insertions(+), 5 deletions(-)
>
> diff --git a/qom/object.c b/qom/object.c
> index f5f416b..f82f12c 100644
> --- a/qom/object.c
> +++ b/qom/object.c
> @@ -457,15 +457,13 @@ ObjectClass *object_class_dynamic_cast(ObjectClass *class,
>  {
>      ObjectClass *ret = NULL;
>      TypeImpl *target_type;
> -    TypeImpl *type;
>  
>      if (!class) {
>          return NULL;
>      }
>  
>      /* A simple fast path that can trigger a lot for leaf classes.  */
> -    type = class->type;
> -    if (type->name == typename) {
> +    if (class->type->name == typename) {

This won't trigger because we unconditionally strdup().  Can you add
this the bit from my patch that sets ->name appropriately?

Aurelien, can you try the resulting series with
--{enable,disable}-qom-casts?  My suspicion is that this is the primary
source of speed up.

If you can make an image available too, I can try this myself.

Regards,

Anthony Liguori

>          return class;
>      }
>  
> @@ -475,7 +473,7 @@ ObjectClass *object_class_dynamic_cast(ObjectClass *class,
>          return NULL;
>      }
>  
> -    if (type->class->interfaces &&
> +    if (class->interfaces &&
>              type_is_ancestor(target_type, type_interface)) {
>          int found = 0;
>          GSList *i;
> @@ -493,7 +491,7 @@ ObjectClass *object_class_dynamic_cast(ObjectClass *class,
>          if (found > 1) {
>              ret = NULL;
>          }
> -    } else if (type_is_ancestor(type, target_type)) {
> +    } else if (type_is_ancestor(class->type, target_type)) {
>          ret = class;
>      }
>  
> -- 
> 1.8.1.4
diff mbox

Patch

diff --git a/qom/object.c b/qom/object.c
index f5f416b..f82f12c 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -457,15 +457,13 @@  ObjectClass *object_class_dynamic_cast(ObjectClass *class,
 {
     ObjectClass *ret = NULL;
     TypeImpl *target_type;
-    TypeImpl *type;
 
     if (!class) {
         return NULL;
     }
 
     /* A simple fast path that can trigger a lot for leaf classes.  */
-    type = class->type;
-    if (type->name == typename) {
+    if (class->type->name == typename) {
         return class;
     }
 
@@ -475,7 +473,7 @@  ObjectClass *object_class_dynamic_cast(ObjectClass *class,
         return NULL;
     }
 
-    if (type->class->interfaces &&
+    if (class->interfaces &&
             type_is_ancestor(target_type, type_interface)) {
         int found = 0;
         GSList *i;
@@ -493,7 +491,7 @@  ObjectClass *object_class_dynamic_cast(ObjectClass *class,
         if (found > 1) {
             ret = NULL;
         }
-    } else if (type_is_ancestor(type, target_type)) {
+    } else if (type_is_ancestor(class->type, target_type)) {
         ret = class;
     }