Skip to content

Commit

Permalink
Let getMessage deal with SSO
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
mkrzewic authored and dennisklein committed Dec 10, 2018
1 parent ee24144 commit 0cb8f61
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions fairmq/MemoryResourceTools.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down

0 comments on commit 0cb8f61

Please sign in to comment.