Skip to content

Commit

Permalink
Different string comparison
Browse files Browse the repository at this point in the history
  • Loading branch information
Mytherin committed May 8, 2021
1 parent c58ea95 commit 93b2d99
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
13 changes: 9 additions & 4 deletions src/include/duckdb/common/operator/comparison_operators.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,20 @@ inline bool LessThan::Operation(bool left, bool right) {
struct StringComparisonOperators {
template <bool INVERSE>
static inline bool EqualsOrNot(const string_t a, const string_t b) {
if (a.IsInlined()) {
auto alen = a.value.inlined.length;
auto blen = b.value.inlined.length;
if (alen != blen) {
return false;
}
if (alen <= string_t::INLINE_LENGTH) {
// small string: compare entire string
if (memcmp(&a, &b, sizeof(string_t)) == 0) {
if (memcmp(&a.value.inlined.inlined, &b.value.inlined.inlined, alen) == 0) {
// entire string is equal
return INVERSE ? false : true;
}
} else {
// large string: first check prefix and length
if (memcmp(&a, &b, sizeof(uint32_t) + string_t::PREFIX_LENGTH) == 0) {
// large string: first check prefix
if (memcmp(a.value.pointer.prefix, b.value.pointer.prefix, string_t::PREFIX_LENGTH) == 0) {
// prefix and length are equal: check main string
if (memcmp(a.value.pointer.ptr, b.value.pointer.ptr, a.GetSize()) == 0) {
// entire string is equal
Expand Down
4 changes: 2 additions & 2 deletions src/include/duckdb/common/types/string_type.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ struct string_t {
if (IsInlined()) {
// zero initialize the prefix first
// this makes sure that strings with length smaller than 4 still have an equal prefix
memset(value.inlined.inlined, 0, INLINE_LENGTH);
memset(value.inlined.inlined, 0, PREFIX_LENGTH);
if (GetSize() == 0) {
return;
}
Expand Down Expand Up @@ -89,7 +89,7 @@ struct string_t {
auto dataptr = (char *)GetDataUnsafe();
if (GetSize() <= INLINE_LENGTH) {
// fill prefix with zeros if the length is smaller than the prefix length
for (idx_t i = GetSize(); i < INLINE_LENGTH; i++) {
for (idx_t i = GetSize(); i < PREFIX_LENGTH; i++) {
value.inlined.inlined[i] = '\0';
}
} else {
Expand Down

0 comments on commit 93b2d99

Please sign in to comment.