[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 15/18] qom: optimize qdev_get_canonical_path using a
From: |
Anthony Liguori |
Subject: |
[Qemu-devel] [PATCH 15/18] qom: optimize qdev_get_canonical_path using a parent link |
Date: |
Wed, 30 Nov 2011 15:03:45 -0600 |
The full tree search was a bit unreasonable.
Signed-off-by: Anthony Liguori <address@hidden>
---
hw/qdev.c | 60 +++++++++++++++++++++++++++---------------------------------
hw/qdev.h | 4 ++++
2 files changed, 31 insertions(+), 33 deletions(-)
diff --git a/hw/qdev.c b/hw/qdev.c
index b944108..7da7196 100644
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -1210,6 +1210,9 @@ void qdev_property_add_child(DeviceState *dev, const char
*name,
qdev_property_add(dev, name, type, qdev_get_child_property,
NULL, NULL, child, errp);
+ g_assert(child->parent == NULL);
+ child->parent = dev;
+
g_free(type);
}
@@ -1282,48 +1285,39 @@ void qdev_property_add_link(DeviceState *dev, const
char *name,
g_free(full_type);
}
-static gchar *qdev_get_path_in(DeviceState *parent, DeviceState *dev)
+gchar *qdev_get_canonical_path(DeviceState *dev)
{
- GSList *i;
+ DeviceState *root = qdev_get_root();
+ char *newpath = NULL, *path = NULL;
- if (parent == dev) {
- return g_strdup("");
- }
-
- for (i = parent->properties; i; i = i->next) {
- DeviceProperty *prop = i->data;
- gchar *subpath;
-
- if (!strstart(prop->type, "child<", NULL)) {
- continue;
- }
+ while (dev != root) {
+ GSList *i;
- /* Check to see if the device is one of parent's children */
- if (prop->opaque == dev) {
- return g_strdup(prop->name);
- }
+ g_assert(dev->parent != NULL);
- /* Check to see if the device is a child of our child */
- subpath = qdev_get_path_in(prop->opaque, dev);
- if (subpath) {
- gchar *path;
+ for (i = dev->parent->properties; i; i = i->next) {
+ DeviceProperty *prop = i->data;
- path = g_strdup_printf("%s/%s", prop->name, subpath);
- g_free(subpath);
+ if (!strstart(prop->type, "child<", NULL)) {
+ continue;
+ }
- return path;
+ if (prop->opaque == dev) {
+ if (path) {
+ newpath = g_strdup_printf("%s/%s", prop->name, path);
+ g_free(path);
+ path = newpath;
+ } else {
+ path = g_strdup(prop->name);
+ }
+ break;
+ }
}
- }
- return NULL;
-}
+ g_assert(i != NULL);
-gchar *qdev_get_canonical_path(DeviceState *dev)
-{
- gchar *path, *newpath;
-
- path = qdev_get_path_in(qdev_get_root(), dev);
- g_assert(path != NULL);
+ dev = dev->parent;
+ }
newpath = g_strdup_printf("/%s", path);
g_free(path);
diff --git a/hw/qdev.h b/hw/qdev.h
index e8c9e76..8eb7ce1 100644
--- a/hw/qdev.h
+++ b/hw/qdev.h
@@ -83,6 +83,10 @@ struct DeviceState {
int instance_id_alias;
int alias_required_for_version;
GSList *properties;
+
+ /* Do not, under any circumstance, use this parent link below anywhere
+ * outside of qdev.c. You have been warned. */
+ DeviceState *parent;
};
typedef void (*bus_dev_printfn)(Monitor *mon, DeviceState *dev, int indent);
--
1.7.4.1
- [Qemu-devel] [PATCH 06/18] qom: add child properties (composition), (continued)
- [Qemu-devel] [PATCH 06/18] qom: add child properties (composition), Anthony Liguori, 2011/11/30
- [Qemu-devel] [PATCH 02/18] qom: register legacy properties as new style properties, Anthony Liguori, 2011/11/30
- [Qemu-devel] [PATCH 08/18] qapi: allow a 'gen' key to suppress code generation, Anthony Liguori, 2011/11/30
- [Qemu-devel] [PATCH 10/18] qom: qom_{get,set} monitor commands, Anthony Liguori, 2011/11/30
- [Qemu-devel] [PATCH 11/18] qdev: add explicitly named devices to the root complex, Anthony Liguori, 2011/11/30
- [Qemu-devel] [PATCH 17/18] Add test tools, Anthony Liguori, 2011/11/30
- [Qemu-devel] [PATCH 16/18] Make qmp.py easier to use, Anthony Liguori, 2011/11/30
- [Qemu-devel] [PATCH 18/18] qdev: split out QOM functions to separate files, Anthony Liguori, 2011/11/30
- [Qemu-devel] [PATCH 13/18] rtc: make piix3 set the rtc as a child, Anthony Liguori, 2011/11/30
- [Qemu-devel] [PATCH 09/18] qmp: add qom-list command, Anthony Liguori, 2011/11/30
- [Qemu-devel] [PATCH 15/18] qom: optimize qdev_get_canonical_path using a parent link,
Anthony Liguori <=
- [Qemu-devel] [PATCH 12/18] dev: add an anonymous peripheral container, Anthony Liguori, 2011/11/30
- [Qemu-devel] [PATCH 14/18] rtc: add a dynamic property for retrieving the date, Anthony Liguori, 2011/11/30
- Re: [Qemu-devel] [PATCH 00/18] qom: dynamic properties and composition tree, Anthony Liguori, 2011/11/30