qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH for-1.5] qom: optimize casting to leaf class and par


From: Anthony Liguori
Subject: [Qemu-devel] [PATCH for-1.5] qom: optimize casting to leaf class and parent class
Date: Fri, 10 May 2013 13:47:55 -0500

Most QOM types use type_register_static but we still strdup the
passed data.  However, the original pointers are useful because
GCC is pretty good about collapsing strings so its very likely any
use of the pointer will end up being that same address.

IOW, with a little trickery, we can compare types by just comparing
strings and in fact that's what we do here.

We do this for the two most common cases, casting to a leaf class
or to the parent class.

With these two changes, I see a decrease from around 2 hash table
lookups to only a thousand with no run time lookups at all.

Cc: Paolo Bonzini <address@hidden>
Cc: Aurelien Jarno <address@hidden>
Cc: Andreas Färber <address@hidden>
Reported-by: Aurelien Jarno <address@hidden>
Signed-off-by: Anthony Liguori <address@hidden>
---
Aurelien, could you please try this patch with your PPC test case?
---
 qom/object.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/qom/object.c b/qom/object.c
index 75e6aac..5ecfd28 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -132,7 +132,13 @@ TypeImpl *type_register(const TypeInfo *info)
 
 TypeImpl *type_register_static(const TypeInfo *info)
 {
-    return type_register(info);
+    TypeImpl *impl;
+
+    impl = type_register(info);
+    impl->name = info->name;
+    impl->parent = info->parent;
+
+    return impl;
 }
 
 static TypeImpl *type_get_by_name(const char *name)
@@ -449,10 +455,16 @@ Object *object_dynamic_cast_assert(Object *obj, const 
char *typename)
 ObjectClass *object_class_dynamic_cast(ObjectClass *class,
                                        const char *typename)
 {
-    TypeImpl *target_type = type_get_by_name(typename);
+    TypeImpl *target_type;
     TypeImpl *type = class->type;
     ObjectClass *ret = NULL;
 
+    if (type->name == typename || type->parent == typename) {
+        return class;
+    }
+
+    target_type = type_get_by_name(typename);
+
     if (!target_type) {
         /* target class type unknown, so fail the cast */
         return NULL;
-- 
1.8.0




reply via email to

[Prev in Thread] Current Thread [Next in Thread]