Skip to content

Commit 8bf1569

Browse files
vef: cleanup (Try)CompareCustomType
Drop "Try" from overload that always runs comparison Return an int since it isn't optional Remove dead branches
1 parent a79bf9d commit 8bf1569

3 files changed

Lines changed: 11 additions & 20 deletions

File tree

sql/sql_executor.cc

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3982,11 +3982,10 @@ static bool cmp_field_value(Field *field, ptrdiff_t diff) {
39823982

39833983
// Use custom comparison function for custom types
39843984
if (field->has_type_context()) {
3985-
if (auto result = villagesql::TryCompareCustomType(
3986-
*field->get_type_context(), field->data_ptr(), value1_length,
3987-
field->data_ptr() + diff, value2_length)) {
3988-
return *result != 0;
3989-
}
3985+
const auto result = villagesql::CompareCustomType(
3986+
*field->get_type_context(), field->data_ptr(), value1_length,
3987+
field->data_ptr() + diff, value2_length);
3988+
return result != 0;
39903989
}
39913990

39923991
// Trailing space can't be skipped and length is different

villagesql/types/util.cc

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -328,13 +328,8 @@ int CustomMemCompare(const Item *item, const uchar *data1, size_t len1,
328328
// Use custom comparison for custom types
329329
if (item != nullptr && item->has_type_context()) {
330330
auto *tc = item->get_type_context();
331-
if (auto result = TryCompareCustomType(*tc, data1, len1, data2, len2)) {
332-
// Handle reverse sort direction in this path only since the comparison
333-
// function assumes ASC but memcmp relies on bits being flipped for DESC.
334-
res = reverse ? -*result : *result;
335-
} else {
336-
res = memcmp(data1, data2, min_len);
337-
}
331+
auto result = CompareCustomType(*tc, data1, len1, data2, len2);
332+
res = reverse ? -result : result;
338333
} else {
339334
res = memcmp(data1, data2, min_len);
340335
}

villagesql/types/util.h

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,8 @@ extern bool InjectAndEncodeCustomType(Item *item, const TypeContext &tc);
140140
// Template version that works with both Item and Field types
141141
// Both Item and Field have has_type_context() and get_type_context() methods
142142
// Overload for TypeContext with binary data
143-
inline std::optional<int> TryCompareCustomType(const TypeContext &tc,
144-
const uchar *data1, size_t len1,
145-
const uchar *data2,
146-
size_t len2) {
143+
inline int CompareCustomType(const TypeContext &tc, const uchar *data1,
144+
size_t len1, const uchar *data2, size_t len2) {
147145
assert(tc.descriptor());
148146
return tc.descriptor()->compare_op().invoke(data1, len1, data2, len2);
149147
}
@@ -156,8 +154,7 @@ std::optional<int> TryCompareCustomType(const T *obj, const uchar *data1,
156154
return std::nullopt;
157155
}
158156

159-
return TryCompareCustomType(*obj->get_type_context(), data1, len1, data2,
160-
len2);
157+
return CompareCustomType(*obj->get_type_context(), data1, len1, data2, len2);
161158
}
162159

163160
// Template overload for comparing two String objects with custom type context
@@ -168,7 +165,7 @@ std::optional<int> TryCompareCustomType(const T *obj, const String &str1,
168165
return std::nullopt;
169166
}
170167

171-
return TryCompareCustomType(
168+
return CompareCustomType(
172169
*obj->get_type_context(), pointer_cast<const uchar *>(str1.ptr()),
173170
str1.length(), pointer_cast<const uchar *>(str2.ptr()), str2.length());
174171
}
@@ -181,7 +178,7 @@ inline std::optional<int> TryCompareCustomType(const TypeContext *tc,
181178
return std::nullopt;
182179
}
183180

184-
return TryCompareCustomType(
181+
return CompareCustomType(
185182
*tc, pointer_cast<const uchar *>(str1.ptr()), str1.length(),
186183
pointer_cast<const uchar *>(str2.ptr()), str2.length());
187184
}

0 commit comments

Comments
 (0)