Commit 63a7b5ee authored by Dominik Charousset's avatar Dominik Charousset

Avoid iterating types twice during message load

parent d6bc6cc6
...@@ -65,6 +65,10 @@ struct meta_object { ...@@ -65,6 +65,10 @@ struct meta_object {
void (*stringify)(std::string&, const void*); void (*stringify)(std::string&, const void*);
}; };
inline bool valid(const meta_object& obj) {
return !obj.type_name.empty();
}
/// Returns the global storage for all meta objects. The ::type_id of an object /// Returns the global storage for all meta objects. The ::type_id of an object
/// is the index for accessing the corresonding meta object. /// is the index for accessing the corresonding meta object.
CAF_CORE_EXPORT span<const meta_object> global_meta_objects(); CAF_CORE_EXPORT span<const meta_object> global_meta_objects();
......
...@@ -73,22 +73,21 @@ bool load_data(Deserializer& source, message::data_ptr& data) { ...@@ -73,22 +73,21 @@ bool load_data(Deserializer& source, message::data_ptr& data) {
&& source.end_field() // && source.end_field() //
&& source.end_object(); && source.end_object();
} }
auto gmos = detail::global_meta_objects();
size_t data_size = 0;
detail::type_id_list_builder ids; detail::type_id_list_builder ids;
ids.reserve(msg_size); ids.reserve(msg_size);
for (size_t i = 0; i < msg_size; ++i) { for (size_t i = 0; i < msg_size; ++i) {
type_id_t id = 0; type_id_t id = 0;
GUARDED(source.value(id)); GUARDED(source.value(id));
ids.push_back(id); if (id < gmos.size() && valid(gmos[id])) {
} ids.push_back(id);
GUARDED(source.end_sequence()); data_size += gmos[id].padded_size;
CAF_ASSERT(ids.size() == msg_size); } else {
size_t data_size = 0;
for (auto id : ids) {
if (auto meta_obj = detail::global_meta_object(id))
data_size += meta_obj->padded_size;
else
STOP(sec::unknown_type); STOP(sec::unknown_type);
}
} }
GUARDED(source.end_sequence());
intrusive_ptr<detail::message_data> ptr; intrusive_ptr<detail::message_data> ptr;
if (auto vptr = malloc(sizeof(detail::message_data) + data_size)) { if (auto vptr = malloc(sizeof(detail::message_data) + data_size)) {
// We don't need to worry about exceptions here: the message_data // We don't need to worry about exceptions here: the message_data
...@@ -99,7 +98,6 @@ bool load_data(Deserializer& source, message::data_ptr& data) { ...@@ -99,7 +98,6 @@ bool load_data(Deserializer& source, message::data_ptr& data) {
} }
auto pos = ptr->storage(); auto pos = ptr->storage();
auto types = ptr->types(); auto types = ptr->types();
auto gmos = detail::global_meta_objects();
GUARDED(source.begin_field("values")); GUARDED(source.begin_field("values"));
GUARDED(source.begin_tuple(msg_size)); GUARDED(source.begin_tuple(msg_size));
for (size_t i = 0; i < msg_size; ++i) { for (size_t i = 0; i < msg_size; ++i) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment