From 608ec9e50fd7b93209a900fe8c5e9a81ccadd99a Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 1 Sep 2009 23:45:30 +0200 Subject: optimize type signature string generation for dbus -1.5k: text data bss dec hex filename 194731 2584 2320 199635 30bd3 abrt.z7/abrt-0.0.8/src/Daemon/.libs/abrt 193117 2592 2320 198029 3058d abrt.z8/abrt-0.0.8/src/Daemon/.libs/abrt Signed-off-by: Denys Vlasenko --- src/Daemon/CommLayerServerDBus.cpp | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) (limited to 'src/Daemon/CommLayerServerDBus.cpp') diff --git a/src/Daemon/CommLayerServerDBus.cpp b/src/Daemon/CommLayerServerDBus.cpp index 0a1e6f0e..0fe63942 100644 --- a/src/Daemon/CommLayerServerDBus.cpp +++ b/src/Daemon/CommLayerServerDBus.cpp @@ -63,23 +63,29 @@ static void store_string(DBusMessageIter* iter, const char* val) /* Templates for vector and map */ template struct type {}; -//template <> struct type { static std::string sig() { return "b"; } }; -template <> struct type { static std::string sig() { return "i"; } }; -template <> struct type { static std::string sig() { return "u"; } }; -template <> struct type { static std::string sig() { return "x"; } }; -template <> struct type { static std::string sig() { return "t"; } }; -template <> struct type { static std::string sig() { return "s"; } }; +//template <> struct type { static const char* csig() { return "b"; } }; +template <> struct type { static const char* csig() { return "i"; } static std::string sig(); }; +template <> struct type { static const char* csig() { return "u"; } static std::string sig(); }; +template <> struct type { static const char* csig() { return "x"; } static std::string sig(); }; +template <> struct type { static const char* csig() { return "t"; } static std::string sig(); }; +template <> struct type { static const char* csig() { return "s"; } static std::string sig(); }; +#define SIG(T) (type::csig() ? type::csig() : type::sig().c_str()) template -struct type< std::vector > { static std::string sig() { return "a" + type::sig(); } }; +struct type< std::vector > { + static const char* csig() { return NULL; } + static std::string sig() { return ssprintf("a%s", SIG(E)); } +}; template -struct type< std::map > { static std::string sig() { return "a{" + type::sig() + type::sig() + "}"; } }; +struct type< std::map > { + static const char* csig() { return NULL; } + static std::string sig() { return ssprintf("a{%s%s}", SIG(K), SIG(V)); } +}; template static void store_vector(DBusMessageIter* iter, const std::vector& val) { DBusMessageIter sub_iter; - const std::string sig = type::sig(); - if (!dbus_message_iter_open_container(iter, DBUS_TYPE_ARRAY, sig.c_str(), &sub_iter)) + if (!dbus_message_iter_open_container(iter, DBUS_TYPE_ARRAY, SIG(E), &sub_iter)) die_out_of_memory(); typename std::vector::const_iterator vit = val.begin(); @@ -102,8 +108,9 @@ template static void store_map(DBusMessageIter* iter, const std::map& val) { DBusMessageIter sub_iter; - const std::string sig = "{" + type::sig() + type::sig() + "}"; - if (!dbus_message_iter_open_container(iter, DBUS_TYPE_ARRAY, sig.c_str(), &sub_iter)) + if (!dbus_message_iter_open_container(iter, DBUS_TYPE_ARRAY, + ssprintf("{%s%s}", SIG(K), SIG(V)).c_str(), + &sub_iter)) die_out_of_memory(); typename std::map::const_iterator mit = val.begin(); -- cgit