Instead of scanning all parent classes every time we walk the list of properties, just make DeviceState subclasses inherit the property list from the parent class.
Signed-off-by: Eduardo Habkost <ehabk...@redhat.com> --- hw/core/qdev-properties.c | 15 +-------------- hw/core/qdev.c | 42 +++++++++++++++--------------------------- qdev-monitor.c | 7 +------ qmp.c | 47 ++++++++++++++++++++++------------------------- 4 files changed, 39 insertions(+), 72 deletions(-) diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c index d506793..d685d72 100644 --- a/hw/core/qdev-properties.c +++ b/hw/core/qdev-properties.c @@ -836,20 +836,7 @@ static Property *qdev_prop_walk(GList *props, const char *name) static Property *qdev_prop_find(DeviceState *dev, const char *name) { - ObjectClass *class; - Property *prop; - - /* device properties */ - class = object_get_class(OBJECT(dev)); - do { - prop = qdev_prop_walk(DEVICE_CLASS(class)->props, name); - if (prop) { - return prop; - } - class = object_class_get_parent(class); - } while (class != object_class_by_name(TYPE_DEVICE)); - - return NULL; + return qdev_prop_walk(DEVICE_GET_CLASS(dev)->props, name); } void error_set_from_qdev_prop_error(Error **errp, int ret, DeviceState *dev, diff --git a/hw/core/qdev.c b/hw/core/qdev.c index b549ae6..bc26b32 100644 --- a/hw/core/qdev.c +++ b/hw/core/qdev.c @@ -919,21 +919,14 @@ void qdev_property_add_static(DeviceState *dev, Property *prop, */ void qdev_alias_all_properties(DeviceState *target, Object *source) { - ObjectClass *class; GList *props; - class = object_get_class(OBJECT(target)); - do { - DeviceClass *dc = DEVICE_CLASS(class); - - for (props = dc->props; props; props = props->next) { - Property *prop = props->data; - object_property_add_alias(source, prop->name, - OBJECT(target), prop->name, - &error_abort); - } - class = object_class_get_parent(class); - } while (class != object_class_by_name(TYPE_DEVICE)); + for (props = DEVICE_GET_CLASS(target)->props; props; props = props->next) { + Property *prop = props->data; + object_property_add_alias(source, prop->name, + OBJECT(target), prop->name, + &error_abort); + } } int qdev_build_hotpluggable_device_list(Object *obj, void *opaque) @@ -1083,7 +1076,7 @@ static void device_set_hotplugged(Object *obj, bool value, Error **err) static void device_initfn(Object *obj) { DeviceState *dev = DEVICE(obj); - ObjectClass *class; + GList *props; if (qdev_hotplug) { dev->hotplugged = 1; @@ -1101,16 +1094,11 @@ static void device_initfn(Object *obj) device_get_hotplugged, device_set_hotplugged, &error_abort); - class = object_get_class(OBJECT(dev)); - do { - GList *props; - for (props = DEVICE_CLASS(class)->props; props; props = props->next) { - Property *prop = props->data; - qdev_property_add_legacy(dev, prop, &error_abort); - qdev_property_add_static(dev, prop, &error_abort); - } - class = object_class_get_parent(class); - } while (class != object_class_by_name(TYPE_DEVICE)); + for (props = DEVICE_GET_CLASS(dev)->props; props; props = props->next) { + Property *prop = props->data; + qdev_property_add_legacy(dev, prop, &error_abort); + qdev_property_add_static(dev, prop, &error_abort); + } object_property_add_link(OBJECT(dev), "parent_bus", TYPE_BUS, (Object **)&dev->parent_bus, NULL, 0, @@ -1169,10 +1157,10 @@ static void device_class_base_init(ObjectClass *class, void *data) { DeviceClass *dc = DEVICE_CLASS(class); - /* We explicitly look up properties in the superclasses, - * so do not propagate them to the subclasses. + /* We inherit properties from the superclass, but we need to fix the + * list pointer that was memcpy()ed. */ - dc->props = NULL; + dc->props = g_list_copy(dc->props); } static void device_unparent(Object *obj) diff --git a/qdev-monitor.c b/qdev-monitor.c index d151dfd..2d5e9f7 100644 --- a/qdev-monitor.c +++ b/qdev-monitor.c @@ -624,7 +624,6 @@ static void bus_print_dev(BusState *bus, Monitor *mon, DeviceState *dev, int ind static void qdev_print(Monitor *mon, DeviceState *dev, int indent) { - ObjectClass *class; BusState *child; NamedGPIOList *ngl; @@ -641,11 +640,7 @@ static void qdev_print(Monitor *mon, DeviceState *dev, int indent) ngl->num_out); } } - class = object_get_class(OBJECT(dev)); - do { - qdev_print_props(mon, dev, DEVICE_CLASS(class)->props, indent); - class = object_class_get_parent(class); - } while (class != object_class_by_name(TYPE_DEVICE)); + qdev_print_props(mon, dev, DEVICE_GET_CLASS(dev)->props, indent); bus_print_dev(dev->parent_bus, mon, dev, indent); QLIST_FOREACH(child, &dev->child_bus, sibling) { qbus_print(mon, child, indent); diff --git a/qmp.c b/qmp.c index 7d91a18..ea32d27 100644 --- a/qmp.c +++ b/qmp.c @@ -446,34 +446,31 @@ static DevicePropertyInfo *make_device_property_info(ObjectClass *klass, const char *description) { DevicePropertyInfo *info; + GList *props; - do { - GList *props; - for (props = DEVICE_CLASS(klass)->props; props; props = props->next) { - Property *prop = props->data; - if (strcmp(name, prop->name) != 0) { - continue; - } - - /* - * TODO Properties without a parser are just for dirty hacks. - * qdev_prop_ptr is the only such PropertyInfo. It's marked - * for removal. This conditional should be removed along with - * it. - */ - if (!prop->info->set) { - return NULL; /* no way to set it, don't show */ - } + for (props = DEVICE_CLASS(klass)->props; props; props = props->next) { + Property *prop = props->data; + if (strcmp(name, prop->name) != 0) { + continue; + } - info = g_malloc0(sizeof(*info)); - info->name = g_strdup(prop->name); - info->type = g_strdup(prop->info->name); - info->has_description = !!prop->info->description; - info->description = g_strdup(prop->info->description); - return info; + /* + * TODO Properties without a parser are just for dirty hacks. + * qdev_prop_ptr is the only such PropertyInfo. It's marked + * for removal. This conditional should be removed along with + * it. + */ + if (!prop->info->set) { + return NULL; /* no way to set it, don't show */ } - klass = object_class_get_parent(klass); - } while (klass != object_class_by_name(TYPE_DEVICE)); + + info = g_malloc0(sizeof(*info)); + info->name = g_strdup(prop->name); + info->type = g_strdup(prop->info->name); + info->has_description = !!prop->info->description; + info->description = g_strdup(prop->info->description); + return info; + } /* Not a qdev property, use the default type */ info = g_malloc0(sizeof(*info)); -- 1.9.3