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-mount.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-mount.c')
-rw-r--r-- | src/dbus-mount.c | 36 |
1 files changed, 21 insertions, 15 deletions
diff --git a/src/dbus-mount.c b/src/dbus-mount.c index 60f1e92415..17d29d6e48 100644 --- a/src/dbus-mount.c +++ b/src/dbus-mount.c @@ -135,23 +135,29 @@ static int bus_mount_append_type(DBusMessageIter *i, const char *property, void return 0; } +static const BusProperty bus_mount_properties[] = { + { "Where", bus_property_append_string, "s", offsetof(Mount, where), true }, + { "What", bus_mount_append_what, "s", 0 }, + { "Options", bus_mount_append_options, "s", 0 }, + { "Type", bus_mount_append_type, "s", 0 }, + { "TimeoutUSec", bus_property_append_usec, "t", offsetof(Mount, timeout_usec) }, + BUS_EXEC_COMMAND_PROPERTY("ExecMount", offsetof(Mount, exec_command[MOUNT_EXEC_MOUNT]), false), + BUS_EXEC_COMMAND_PROPERTY("ExecUnmount", offsetof(Mount, exec_command[MOUNT_EXEC_UNMOUNT]), false), + BUS_EXEC_COMMAND_PROPERTY("ExecRemount", offsetof(Mount, exec_command[MOUNT_EXEC_REMOUNT]), false), + { "ControlPID", bus_property_append_pid, "u", offsetof(Mount, control_pid) }, + { "DirectoryMode", bus_property_append_mode, "u", offsetof(Mount, directory_mode) }, + { NULL, } +}; + DBusHandlerResult bus_mount_message_handler(Unit *u, DBusConnection *c, DBusMessage *message) { Mount *m = MOUNT(u); - const BusProperty properties[] = { - BUS_UNIT_PROPERTIES, - { "org.freedesktop.systemd1.Mount", "Where", bus_property_append_string, "s", m->where }, - { "org.freedesktop.systemd1.Mount", "What", bus_mount_append_what, "s", u }, - { "org.freedesktop.systemd1.Mount", "Options", bus_mount_append_options, "s", u }, - { "org.freedesktop.systemd1.Mount", "Type", bus_mount_append_type, "s", u }, - { "org.freedesktop.systemd1.Mount", "TimeoutUSec", bus_property_append_usec, "t", &m->timeout_usec }, - BUS_EXEC_COMMAND_PROPERTY("org.freedesktop.systemd1.Mount", m->exec_command+MOUNT_EXEC_MOUNT, "ExecMount"), - BUS_EXEC_COMMAND_PROPERTY("org.freedesktop.systemd1.Mount", m->exec_command+MOUNT_EXEC_UNMOUNT, "ExecUnmount"), - BUS_EXEC_COMMAND_PROPERTY("org.freedesktop.systemd1.Mount", m->exec_command+MOUNT_EXEC_REMOUNT, "ExecRemount"), - BUS_EXEC_CONTEXT_PROPERTIES("org.freedesktop.systemd1.Mount", m->exec_context), - { "org.freedesktop.systemd1.Mount", "ControlPID", bus_property_append_pid, "u", &m->control_pid }, - { "org.freedesktop.systemd1.Mount", "DirectoryMode", bus_property_append_mode, "u", &m->directory_mode }, - { NULL, NULL, NULL, NULL, NULL } + + const BusBoundProperties bps[] = { + { "org.freedesktop.systemd1.Unit", bus_unit_properties, u }, + { "org.freedesktop.systemd1.Mount", bus_mount_properties, m }, + { "org.freedesktop.systemd1.Mount", bus_exec_context_properties, &m->exec_context }, + { NULL, } }; - return bus_default_message_handler(c, message, INTROSPECTION, INTERFACES_LIST, properties); + return bus_default_message_handler(c, message, INTROSPECTION, INTERFACES_LIST, bps ); } |