perf: optimize serialization of arrays of trivial D-Bus types (#340)

* Improve performance of std::vector<> per Issue #339.

* refactor: improve performance of vector serialization

---------

Co-authored-by: Plinio Andrade <plinio.andrade@oracle.com>
Co-authored-by: Stanislav Angelovič <stanislav.angelovic@protonmail.com>
This commit is contained in:
pliniofpa
2023-07-27 18:31:49 +02:00
committed by GitHub
co-authored by Plinio Andrade Stanislav Angelovič
parent 98f4929337
commit 29c877a89a
3 changed files with 127 additions and 56 deletions
Regular → Executable
+14
View File
@@ -226,6 +226,11 @@ Message& Message::operator<<(const UnixFd &item)
return *this;
}
void Message::appendArray(char type, const void *ptr, size_t size)
{
auto r = sd_bus_message_append_array((sd_bus_message*)msg_, type, ptr, size);
SDBUS_THROW_ERROR_IF(r < 0, "Failed to serialize an array", -r);
}
Message& Message::operator>>(bool& item)
{
@@ -318,6 +323,15 @@ Message& Message::operator>>(uint64_t& item)
return *this;
}
void Message::readArray(char type, const void **ptr, size_t *size)
{
auto r = sd_bus_message_read_array((sd_bus_message*)msg_, type, ptr, size);
if (r == 0)
ok_ = false;
SDBUS_THROW_ERROR_IF(r < 0, "Failed to deserialize an array", -r);
}
Message& Message::operator>>(double& item)
{
auto r = sd_bus_message_read_basic((sd_bus_message*)msg_, SD_BUS_TYPE_DOUBLE, &item);