diff --git a/types.cc b/types.cc index 4407950db8..6fc68eeb97 100644 --- a/types.cc +++ b/types.cc @@ -6,28 +6,43 @@ #include "cql3/cql3_type.hh" #include "types.hh" -template -bool -abstract_type::default_less(bytes_view v1, bytes_view v2, Compare compare) { - auto o1 = deserialize(v1); - auto o2 = deserialize(v2); - if (!o1) { - return bool(o2); +template +struct simple_type_traits { + static T read_nonempty(bytes_view v) { + return read_simple_exactly(v); } - if (!o2) { - return false; - } - auto& x1 = boost::any_cast(*o1); - auto& x2 = boost::any_cast(*o2); - return compare(x1, x2); -} +}; +template<> +struct simple_type_traits { + static bool read_nonempty(bytes_view v) { + return read_simple_exactly(v) != 0; + } +}; + +template<> +struct simple_type_traits { + static db_clock::time_point read_nonempty(bytes_view v) { + return db_clock::time_point(db_clock::duration(read_simple_exactly(v))); + } +}; template struct simple_type_impl : abstract_type { simple_type_impl(sstring name) : abstract_type(std::move(name)) {} + virtual int32_t compare(bytes_view v1, bytes_view v2) override { + if (v1.empty()) { + return v2.empty() ? 0 : -1; + } + if (v2.empty()) { + return 1; + } + T a = simple_type_traits::read_nonempty(v1); + T b = simple_type_traits::read_nonempty(v2); + return a == b ? 0 : a < b ? -1 : 1; + } virtual bool less(bytes_view v1, bytes_view v2) override { - return default_less(v1, v2); + return compare(v1, v2) < 0; } virtual bool is_byte_order_equal() const override { return true; diff --git a/types.hh b/types.hh index b3b4f08f63..3606fbc768 100644 --- a/types.hh +++ b/types.hh @@ -128,9 +128,6 @@ public: virtual bool is_collection() { return false; } virtual bool is_multi_cell() { return false; } virtual ::shared_ptr as_cql3_type() = 0; -protected: - template > - bool default_less(bytes_view b1, bytes_view b2, Compare compare = Compare()); }; using data_type = shared_ptr;