diff options
author | Michal Schmidt <mschmidt@redhat.com> | 2012-01-16 00:23:59 +0100 |
---|---|---|
committer | Michal Schmidt <mschmidt@redhat.com> | 2012-01-16 13:34:42 +0100 |
commit | d200735e13c52dcfe36c0e066f9f6c2fbfb85a9c (patch) | |
tree | c8ba5a460ecd34fe1f60a09da6c09c43648a2f6b /src/dbus-job.c | |
parent | 595ed347a87e69893c5e72168fc2e94a7cb09e73 (diff) |
dbus: more efficient implementation of properties
The way the various properties[] arrays are initialized is inefficient:
- only the .data members change at runtime, yet the whole arrays of
properties with all the fields are constructed on the stack one by
one by the code.
- there's duplication, eg. the properties of "org.freedesktop.systemd1.Unit"
are repeated in several unit types.
Fix it by moving the information about properties into static const
sections. Instead of storing the .data directly in the property, store
a constant offset from a run-time base.
The small arrays of struct BusBoundProperties bind together the constant
information with the right runtime information (the base pointer).
On my system the code shrinks by 60 KB, data increases by 10 KB.
Diffstat (limited to 'src/dbus-job.c')
-rw-r--r-- | src/dbus-job.c | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/src/dbus-job.c b/src/dbus-job.c index 82a23a85bd..ab6d610243 100644 --- a/src/dbus-job.c +++ b/src/dbus-job.c @@ -85,15 +85,15 @@ static int bus_job_append_unit(DBusMessageIter *i, const char *property, void *d return 0; } -static DBusHandlerResult bus_job_message_dispatch(Job *j, DBusConnection *connection, DBusMessage *message) { - const BusProperty properties[] = { - { "org.freedesktop.systemd1.Job", "Id", bus_property_append_uint32, "u", &j->id }, - { "org.freedesktop.systemd1.Job", "State", bus_job_append_state, "s", &j->state }, - { "org.freedesktop.systemd1.Job", "JobType", bus_job_append_type, "s", &j->type }, - { "org.freedesktop.systemd1.Job", "Unit", bus_job_append_unit, "(so)", j }, - { NULL, NULL, NULL, NULL, NULL } - }; +static const BusProperty bus_job_properties[] = { + { "Id", bus_property_append_uint32, "u", offsetof(Job, id) }, + { "State", bus_job_append_state, "s", offsetof(Job, state) }, + { "JobType", bus_job_append_type, "s", offsetof(Job, type) }, + { "Unit", bus_job_append_unit, "(so)", 0 }, + { NULL, } +}; +static DBusHandlerResult bus_job_message_dispatch(Job *j, DBusConnection *connection, DBusMessage *message) { DBusMessage *reply = NULL; if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Job", "Cancel")) { @@ -102,8 +102,13 @@ static DBusHandlerResult bus_job_message_dispatch(Job *j, DBusConnection *connec job_finish_and_invalidate(j, JOB_CANCELED); - } else - return bus_default_message_handler(connection, message, INTROSPECTION, INTERFACES_LIST, properties); + } else { + const BusBoundProperties bps[] = { + { "org.freedesktop.systemd1.Job", bus_job_properties, j }, + { NULL, } + }; + return bus_default_message_handler(connection, message, INTROSPECTION, INTERFACES_LIST, bps); + } if (reply) { if (!dbus_connection_send(connection, reply, NULL)) |