From b15db851fed62807a1b595f1130b5ff9dac83a8f Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Fri, 11 Feb 2022 09:46:06 -0500 Subject: [PATCH] LibSQL: Short-circuit single-element tuple comparisons If a tuple has a single value, perform a comparison using that singular value. This allows, for example, comparisons of the form "(1) < 4", where (1) is a single element tuple. --- Userland/Libraries/LibSQL/Value.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Userland/Libraries/LibSQL/Value.cpp b/Userland/Libraries/LibSQL/Value.cpp index d912c4fbd6..e41f6dad51 100644 --- a/Userland/Libraries/LibSQL/Value.cpp +++ b/Userland/Libraries/LibSQL/Value.cpp @@ -983,8 +983,11 @@ bool TupleImpl::can_cast(Value const& other_value) const int TupleImpl::compare(Value const& other) const { - if (other.type() != SQLType::Tuple) + if (other.type() != SQLType::Tuple) { + if (size() == 1) + return Value(value().at(0)).compare(other); return 1; + } auto& other_impl = other.get_impl({}); if (m_descriptor && other_impl.m_descriptor && m_descriptor->compare_ignoring_names(*other_impl.m_descriptor))