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-common.h | |
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-common.h')
-rw-r--r-- | src/dbus-common.h | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/src/dbus-common.h b/src/dbus-common.h index acd9208d66..c3499b999f 100644 --- a/src/dbus-common.h +++ b/src/dbus-common.h @@ -96,14 +96,22 @@ typedef int (*BusPropertyCallback)(DBusMessageIter *iter, const char *property, typedef int (*BusPropertySetCallback)(DBusMessageIter *iter, const char *property); typedef struct BusProperty { - const char *interface; /* interface of the property */ const char *property; /* name of the property */ BusPropertyCallback append; /* Function that is called to serialize this property */ const char *signature; - const void *data; /* The data of this property */ + const uint16_t offset; /* Offset from BusBoundProperties::base address to the property data. + * uint16_t is sufficient, because we have no structs too big. + * -Werror=overflow will catch it if this does not hold. */ + bool indirect; /* data is indirect, ie. not base+offset, but *(base+offset) */ BusPropertySetCallback set; /* Optional: Function that is called to set this property */ } BusProperty; +typedef struct BusBoundProperties { + const char *interface; /* interface of the properties */ + const BusProperty *properties; /* array of properties, ended by a NULL-filled element */ + const void *const base; /* base pointer to which the offset must be added to reach data */ +} BusBoundProperties; + DBusHandlerResult bus_send_error_reply( DBusConnection *c, DBusMessage *message, @@ -115,7 +123,7 @@ DBusHandlerResult bus_default_message_handler( DBusMessage *message, const char *introspection, const char *interfaces, - const BusProperty *properties); + const BusBoundProperties *bound_properties); int bus_property_append_string(DBusMessageIter *i, const char *property, void *data); int bus_property_append_strv(DBusMessageIter *i, const char *property, void *data); |