From 73dc55155ec2795cd96ff94fd00d023378e905f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrien=20B=C3=A9raud?= <> Date: Wed, 4 Feb 2026 15:20:13 -0500 Subject: [PATCH] utils: make unpackMsg take const Blob& and inline Change the template unpackMsg to accept a const Blob& to avoid an unnecessary copy of the Blob argument. Move the non-template unpackMsg (returning msgpack::unpacked) into the header as an inline function and remove its out-of-line definition from src/utils.cpp. Update declarations accordingly. --- include/opendht/utils.h | 8 ++++++-- src/utils.cpp | 6 ------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/include/opendht/utils.h b/include/opendht/utils.h index 3c4a7bd3..69707cea 100644 --- a/include/opendht/utils.h +++ b/include/opendht/utils.h @@ -172,13 +172,17 @@ packMsg(const Type& t) template Type -unpackMsg(Blob b) +unpackMsg(const Blob& b) { msgpack::unpacked msg_res = msgpack::unpack((const char*) b.data(), b.size()); return msg_res.get().as(); } -msgpack::unpacked unpackMsg(Blob b); +inline msgpack::unpacked +unpackMsg(const Blob& b) +{ + return msgpack::unpack((const char*) b.data(), b.size()); +} msgpack::object* findMapValue(const msgpack::object& map, const char* key, size_t length); diff --git a/src/utils.cpp b/src/utils.cpp index 56e05e22..a28a2735 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -282,12 +282,6 @@ unpackBlob(const msgpack::object& o) } } -msgpack::unpacked -unpackMsg(Blob b) -{ - return msgpack::unpack((const char*) b.data(), b.size()); -} - msgpack::object* findMapValue(const msgpack::object& map, const char* key, size_t key_length) {