From 0cb8f6166a33af1890a0ccc573c8864c375d9c3a Mon Sep 17 00:00:00 2001 From: mkrzewic Date: Fri, 7 Dec 2018 13:15:53 +0100 Subject: [PATCH] Let getMessage deal with SSO containers are not required to allocate, e.g. small string optimization for now this is hypothetical since we cannot use std::basic_string with at least gcc 7 since the basic_string there still uses the deprecated rebind allocator interface (which pmr does not implement) --- fairmq/MemoryResourceTools.h | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/fairmq/MemoryResourceTools.h b/fairmq/MemoryResourceTools.h index 54e1084a..e6e8f094 100644 --- a/fairmq/MemoryResourceTools.h +++ b/fairmq/MemoryResourceTools.h @@ -45,15 +45,21 @@ FairMQMessagePtr getMessage(ContainerT &&container_, FairMQMemoryResource *targe const_cast::type *>( container.data()))); if (message) + { message->SetUsedSize(containerSizeBytes); - return message; - } else { - auto message = targetResource->getTransportFactory()->CreateMessage(containerSizeBytes); - std::memcpy(static_cast(message->GetData()), - container.data(), - containerSizeBytes); - return message; + return message; + } else { + //container is not required to allocate (like in std::string small string optimization) + //in case we get no message we fall back to default (copy) behaviour) + targetResource = resource; + } } + + auto message = targetResource->getTransportFactory()->CreateMessage(containerSizeBytes); + std::memcpy(static_cast(message->GetData()), + container.data(), + containerSizeBytes); + return message; }; } /* namespace mq */