2
0
Эх сурвалжийг харах

qom: use object_new_with_class when possible

A small optimization/code simplification, that also makes it clear that
we won't look for a type in a not-loaded-yet module---the module will
have been loaded by a call to module_object_class_by_name(), if present.

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Paolo Bonzini 9 сар өмнө
parent
commit
b801e3cb2a

+ 3 - 2
hw/core/qdev.c

@@ -167,10 +167,11 @@ DeviceState *qdev_new(const char *name)
 
 
 DeviceState *qdev_try_new(const char *name)
 DeviceState *qdev_try_new(const char *name)
 {
 {
-    if (!module_object_class_by_name(name)) {
+    ObjectClass *oc = module_object_class_by_name(name);
+    if (!oc) {
         return NULL;
         return NULL;
     }
     }
-    return DEVICE(object_new(name));
+    return DEVICE(object_new_with_class(oc));
 }
 }
 
 
 static QTAILQ_HEAD(, DeviceListener) device_listeners
 static QTAILQ_HEAD(, DeviceListener) device_listeners

+ 1 - 1
qom/object_interfaces.c

@@ -108,7 +108,7 @@ Object *user_creatable_add_type(const char *type, const char *id,
     }
     }
 
 
     assert(qdict);
     assert(qdict);
-    obj = object_new(type);
+    obj = object_new_with_class(klass);
     object_set_properties_from_qdict(obj, qdict, v, &local_err);
     object_set_properties_from_qdict(obj, qdict, v, &local_err);
     if (local_err) {
     if (local_err) {
         goto out;
         goto out;

+ 1 - 1
qom/qom-qmp-cmds.c

@@ -141,7 +141,7 @@ ObjectPropertyInfoList *qmp_device_list_properties(const char *typename,
         return NULL;
         return NULL;
     }
     }
 
 
-    obj = object_new(typename);
+    obj = object_new_with_class(klass);
 
 
     object_property_iter_init(&iter, obj);
     object_property_iter_init(&iter, obj);
     while ((prop = object_property_iter_next(&iter))) {
     while ((prop = object_property_iter_next(&iter))) {