mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-23 05:45:35 +08:00
[xswiftbus] Use std::string_view for performance in CDBusMessage
This avoids repeated dynamic memory allocations in dbusMessageHandler methods and elsewhere due to repeatedly constructing temporary strings. std::string_view is a C++17 feature but also part of the Library Fundamentals TS and available in all our compilers.
This commit is contained in:
@@ -61,17 +61,17 @@ namespace XSwiftBus
|
|||||||
return dbus_message_get_serial(m_message);
|
return dbus_message_get_serial(m_message);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string CDBusMessage::getInterfaceName() const
|
string_view CDBusMessage::getInterfaceName() const
|
||||||
{
|
{
|
||||||
return dbus_message_get_interface(m_message);
|
return dbus_message_get_interface(m_message);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string CDBusMessage::getObjectPath() const
|
string_view CDBusMessage::getObjectPath() const
|
||||||
{
|
{
|
||||||
return dbus_message_get_path(m_message);
|
return dbus_message_get_path(m_message);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string CDBusMessage::getMethodName() const
|
string_view CDBusMessage::getMethodName() const
|
||||||
{
|
{
|
||||||
return dbus_message_get_member(m_message);
|
return dbus_message_get_member(m_message);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,10 +12,23 @@
|
|||||||
#include "dbus/dbus.h"
|
#include "dbus/dbus.h"
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#if defined(_MSC_VER)
|
||||||
|
#include <experimental/string>
|
||||||
|
#elif defined(__clang__)
|
||||||
|
#include <string_view>
|
||||||
|
#else
|
||||||
|
#include <experimental/string_view>
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace XSwiftBus
|
namespace XSwiftBus
|
||||||
{
|
{
|
||||||
|
|
||||||
|
#if defined(_MSC_VER) || defined(__clang__)
|
||||||
|
using std::string_view;
|
||||||
|
#else
|
||||||
|
using std::experimental::string_view;
|
||||||
|
#endif
|
||||||
|
|
||||||
//! DBus Message
|
//! DBus Message
|
||||||
class CDBusMessage
|
class CDBusMessage
|
||||||
{
|
{
|
||||||
@@ -45,13 +58,13 @@ namespace XSwiftBus
|
|||||||
dbus_uint32_t getSerial() const;
|
dbus_uint32_t getSerial() const;
|
||||||
|
|
||||||
//! Get the called interface name
|
//! Get the called interface name
|
||||||
std::string getInterfaceName() const;
|
string_view getInterfaceName() const;
|
||||||
|
|
||||||
//! Get the called object path
|
//! Get the called object path
|
||||||
std::string getObjectPath() const;
|
string_view getObjectPath() const;
|
||||||
|
|
||||||
//! Get the called method name
|
//! Get the called method name
|
||||||
std::string getMethodName() const;
|
string_view getMethodName() const;
|
||||||
|
|
||||||
//! Begin writing argument
|
//! Begin writing argument
|
||||||
void beginArgumentWrite();
|
void beginArgumentWrite();
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ TEMPLATE = lib
|
|||||||
CONFIG += shared plugin
|
CONFIG += shared plugin
|
||||||
CONFIG -= qt
|
CONFIG -= qt
|
||||||
|
|
||||||
|
CONFIG += c++17
|
||||||
|
|
||||||
INCLUDEPATH += $$EXTERNALSROOT/common/include/XPLM
|
INCLUDEPATH += $$EXTERNALSROOT/common/include/XPLM
|
||||||
|
|
||||||
LIBS += -levent_core -ldbus-1
|
LIBS += -levent_core -ldbus-1
|
||||||
|
|||||||
Reference in New Issue
Block a user