diff --git a/types.cc b/types.cc index 7d1e4daa2b..6f0efa5d88 100644 --- a/types.cc +++ b/types.cc @@ -1743,9 +1743,6 @@ public: virtual bool less(bytes_view v1, bytes_view v2) const override { return less_unsigned(v1, v2); } - virtual bool references_duration() const override { - return true; - } private: using counter_type = cql_duration::common_counter_type; @@ -2159,6 +2156,21 @@ bool abstract_type::is_multi_cell() const { bool abstract_type::is_native() const { return !is_collection() && !is_tuple(); } +bool abstract_type::references_duration() const { + struct visitor { + bool operator()(const abstract_type&) { return false; } + bool operator()(const duration_type_impl&) { return true; } + bool operator()(const tuple_type_impl& t) { + return boost::algorithm::any_of(t.all_types(), std::mem_fn(&abstract_type::references_duration)); + } + bool operator()(const map_type_impl& m) { + return m.get_keys_type()->references_duration() || m.get_values_type()->references_duration(); + } + bool operator()(const listlike_collection_type_impl& l) { return l.get_elements_type()->references_duration(); } + }; + return visit(*this, visitor{}); +} + abstract_type::cql3_kind abstract_type::get_cql3_kind_impl() const { struct visitor { cql3_kind operator()(const ascii_type_impl&) { return cql3_kind::ASCII; } @@ -2558,10 +2570,6 @@ map_type_impl::update_user_type(const shared_ptr updated) get_instance(k ? *k : _keys, v ? *v : _values, _is_multi_cell))); } -bool map_type_impl::references_duration() const { - return _keys->references_duration() || _values->references_duration(); -} - auto collection_type_impl::deserialize_mutation_form(bytes_view in) const -> mutation_view { mutation_view ret; auto has_tomb = read_simple(in); @@ -3019,10 +3027,6 @@ set_type_impl::update_user_type(const shared_ptr updated) return std::nullopt; } -bool set_type_impl::references_duration() const { - return _elements->references_duration(); -} - list_type list_type_impl::get_instance(data_type elements, bool is_multi_cell) { return intern::get_instance(elements, is_multi_cell); @@ -3235,10 +3239,6 @@ list_type_impl::update_user_type(const shared_ptr updated) return std::nullopt; } -bool list_type_impl::references_duration() const { - return _elements->references_duration(); -} - tuple_type_impl::tuple_type_impl(kind k, sstring name, std::vector types) : concrete_type(k, std::move(name), { }, data::type_info::make_variable_size()), _types(std::move(types)) { for (auto& t : _types) { @@ -3705,10 +3705,6 @@ tuple_type_impl::update_user_type(const shared_ptr updated return std::nullopt; } -bool tuple_type_impl::references_duration() const { - return boost::algorithm::any_of(_types, std::mem_fn(&abstract_type::references_duration)); -} - sstring user_type_impl::get_name_as_string() const { auto real_utf8_type = static_cast(utf8_type.get()); diff --git a/types.hh b/types.hh index e92b757fb7..b043a8f5ec 100644 --- a/types.hh +++ b/types.hh @@ -568,9 +568,7 @@ public: } virtual bool references_user_type(const sstring& keyspace, const bytes& name) const = 0; virtual std::optional update_user_type(const shared_ptr updated) const = 0; - virtual bool references_duration() const { - return false; - } + bool references_duration() const; std::optional value_length_if_fixed() const { return _value_length_if_fixed; } diff --git a/types/list.hh b/types/list.hh index 62282b4d0d..97d5a5747e 100644 --- a/types/list.hh +++ b/types/list.hh @@ -62,7 +62,6 @@ public: virtual bytes to_value(mutation_view mut, cql_serialization_format sf) const override; virtual bool references_user_type(const sstring& keyspace, const bytes& name) const override; virtual std::optional update_user_type(const shared_ptr updated) const override; - virtual bool references_duration() const override; }; data_value make_list_value(data_type type, list_type_impl::native_type value); diff --git a/types/map.hh b/types/map.hh index 9474577148..eaf757ad37 100644 --- a/types/map.hh +++ b/types/map.hh @@ -72,7 +72,6 @@ public: virtual bytes to_value(mutation_view mut, cql_serialization_format sf) const override; virtual bool references_user_type(const sstring& keyspace, const bytes& name) const override; virtual std::optional update_user_type(const shared_ptr updated) const override; - virtual bool references_duration() const override; }; data_value make_map_value(data_type tuple_type, map_type_impl::native_type value); diff --git a/types/set.hh b/types/set.hh index 927903b20a..a8991b4593 100644 --- a/types/set.hh +++ b/types/set.hh @@ -64,7 +64,6 @@ public: const std::vector& v, cql_serialization_format sf) const; virtual bool references_user_type(const sstring& keyspace, const bytes& name) const override; virtual std::optional update_user_type(const shared_ptr updated) const override; - virtual bool references_duration() const override; }; data_value make_set_value(data_type tuple_type, set_type_impl::native_type value); diff --git a/types/tuple.hh b/types/tuple.hh index 49e5259b7b..0922205313 100644 --- a/types/tuple.hh +++ b/types/tuple.hh @@ -138,7 +138,6 @@ public: virtual bool is_value_compatible_with_internal(const abstract_type& previous) const override; virtual bool references_user_type(const sstring& keyspace, const bytes& name) const override; virtual std::optional update_user_type(const shared_ptr updated) const override; - virtual bool references_duration() const override; private: bool check_compatibility(const abstract_type& previous, bool (abstract_type::*predicate)(const abstract_type&) const) const; static sstring make_name(const std::vector& types);