Commit ac19cd13 authored by Dominik Charousset's avatar Dominik Charousset

Refactor `tuple_type_names()`: return string value

parent 1b7f9e56
......@@ -72,8 +72,6 @@ class decorated_tuple : public message_data {
const char* uniform_name_at(size_t pos) const override;
const std::string* tuple_type_names() const override;
uint16_t type_nr_at(size_t pos) const override;
private:
......
......@@ -55,7 +55,7 @@ class message_data : public ref_counted {
virtual const void* at(size_t pos) const = 0;
virtual const std::string* tuple_type_names() const = 0;
std::string tuple_type_names() const;
/**
* Tries to match element at position `pos` to given RTTI.
......@@ -132,8 +132,6 @@ class message_data : public ref_counted {
};
};
std::string get_tuple_type_names(const detail::message_data&);
} // namespace detail
} // namespace caf
......
......@@ -120,12 +120,6 @@ class tuple_vals : public message_data {
return const_cast<void*>(at(pos));
}
const std::string* tuple_type_names() const override {
// produced name is equal for all instances
static std::string result = get_tuple_type_names(*this);
return &result;
}
bool match_element(size_t pos, uint16_t typenr,
const std::type_info* rtti) const override {
CAF_REQUIRE(pos < size());
......
......@@ -91,11 +91,5 @@ decorated_tuple::decorated_tuple(pointer d, size_t offset)
init(offset);
}
const std::string* decorated_tuple::tuple_type_names() const {
// produced name is equal for all instances
static std::string result = get_tuple_type_names(*this);
return &result;
}
} // namespace detail
} // namespace caf
......@@ -62,11 +62,11 @@ void* message_data::mutable_native_data() {
return nullptr;
}
std::string get_tuple_type_names(const detail::message_data& tup) {
std::string message_data::tuple_type_names() const {
std::string result = "@<>";
for (size_t i = 0; i < tup.size(); ++i) {
for (size_t i = 0; i < size(); ++i) {
result += "+";
result += tup.uniform_name_at(i);
result += uniform_name_at(i);
}
return result;
}
......
......@@ -232,13 +232,7 @@ void deserialize_impl(channel& ptrref, deserializer* source) {
void serialize_impl(const message& tup, serializer* sink) {
std::string dynamic_name; // used if tup holds an object_array
// ttn can be nullptr even if tuple is not empty (in case of object_array)
const std::string* ttn = tup.empty() ? nullptr : tup.tuple_type_names();
const char* tname = ttn ? ttn->data() : (tup.empty() ? "@<>" : nullptr);
if (!tname) {
// tuple is not empty, i.e., we are dealing with an object array
dynamic_name = detail::get_tuple_type_names(*tup.vals());
tname = dynamic_name.c_str();
}
std::string tname = tup.empty() ? "@<>" : tup.tuple_type_names();
auto uti_map = detail::singletons::get_uniform_type_info_map();
auto uti = uti_map->by_uniform_name(tname);
if (uti == nullptr) {
......
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