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)
This commit is contained in:
mkrzewic 2018-12-07 13:15:53 +01:00 committed by Dennis Klein
parent ee24144d61
commit 0cb8f6166a

View File

@ -45,15 +45,21 @@ FairMQMessagePtr getMessage(ContainerT &&container_, FairMQMemoryResource *targe
const_cast<typename std::remove_const<typename ContainerT::value_type>::type *>(
container.data())));
if (message)
{
message->SetUsedSize(containerSizeBytes);
return message;
} else {
auto message = targetResource->getTransportFactory()->CreateMessage(containerSizeBytes);
std::memcpy(static_cast<fair::mq::byte *>(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<fair::mq::byte *>(message->GetData()),
container.data(),
containerSizeBytes);
return message;
};
} /* namespace mq */