Skip to content

Commit

Permalink
Merge branch 'master' into chore/fix-build
Browse files Browse the repository at this point in the history
  • Loading branch information
LittleFall authored Dec 29, 2022
2 parents 3b2a3ba + c9eb6e6 commit 10e188f
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 9 deletions.
21 changes: 16 additions & 5 deletions dbms/src/Common/HashTable/StringHashTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,6 @@ class StringHashTable : private boost::noncopyable
// 1. Always memcpy 8 times bytes
// 2. Use switch case extension to generate fast dispatching table
// 3. Funcs are named callables that can be force_inlined
// NOTE: It relies on Little Endianness
template <typename Self, typename KeyHolder, typename Func>
static auto
#if defined(ADDRESS_SANITIZER) || defined(THREAD_SANITIZER)
Expand Down Expand Up @@ -296,13 +295,19 @@ class StringHashTable : private boost::noncopyable
if ((reinterpret_cast<uintptr_t>(p) & 2048) == 0)
{
memcpy(&n[0], p, 8);
n[0] &= -1ul >> s;
if constexpr (DB::isLittleEndian())
n[0] &= (-1ULL >> s);
else
n[0] &= (-1ULL << s);
}
else
{
const char * lp = x.data + x.size - 8;
memcpy(&n[0], lp, 8);
n[0] >>= s;
if constexpr (DB::isLittleEndian())
n[0] >>= s;
else
n[0] <<= s;
}
keyHolderDiscardKey(key_holder);
return func(self.m1, k8, hash(k8));
Expand All @@ -312,7 +317,10 @@ class StringHashTable : private boost::noncopyable
memcpy(&n[0], p, 8);
const char * lp = x.data + x.size - 8;
memcpy(&n[1], lp, 8);
n[1] >>= s;
if constexpr (DB::isLittleEndian())
n[1] >>= s;
else
n[1] <<= s;
keyHolderDiscardKey(key_holder);
return func(self.m2, k16, hash(k16));
}
Expand All @@ -321,7 +329,10 @@ class StringHashTable : private boost::noncopyable
memcpy(&n[0], p, 16);
const char * lp = x.data + x.size - 8;
memcpy(&n[2], lp, 8);
n[2] >>= s;
if constexpr (DB::isLittleEndian())
n[2] >>= s;
else
n[2] <<= s;
keyHolderDiscardKey(key_holder);
return func(self.m3, k24, hash(k24));
}
Expand Down
20 changes: 16 additions & 4 deletions dbms/src/Common/HashTable/TwoLevelStringHashTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,19 @@ class TwoLevelStringHashTable : private boost::noncopyable
if ((reinterpret_cast<uintptr_t>(p) & 2048) == 0)
{
memcpy(&n[0], p, 8);
n[0] &= -1ul >> s;
if constexpr (DB::isLittleEndian())
n[0] &= (-1ULL >> s);
else
n[0] &= (-1ULL << s);
}
else
{
const char * lp = x.data + x.size - 8;
memcpy(&n[0], lp, 8);
n[0] >>= s;
if constexpr (DB::isLittleEndian())
n[0] >>= s;
else
n[0] <<= s;
}
auto res = hash(k8);
auto buck = getBucketFromHash(res);
Expand All @@ -150,7 +156,10 @@ class TwoLevelStringHashTable : private boost::noncopyable
memcpy(&n[0], p, 8);
const char * lp = x.data + x.size - 8;
memcpy(&n[1], lp, 8);
n[1] >>= s;
if constexpr (DB::isLittleEndian())
n[1] >>= s;
else
n[1] <<= s;
auto res = hash(k16);
auto buck = getBucketFromHash(res);
keyHolderDiscardKey(key_holder);
Expand All @@ -161,7 +170,10 @@ class TwoLevelStringHashTable : private boost::noncopyable
memcpy(&n[0], p, 16);
const char * lp = x.data + x.size - 8;
memcpy(&n[2], lp, 8);
n[2] >>= s;
if constexpr (DB::isLittleEndian())
n[2] >>= s;
else
n[2] <<= s;
auto res = hash(k24);
auto buck = getBucketFromHash(res);
keyHolderDiscardKey(key_holder);
Expand Down
5 changes: 5 additions & 0 deletions dbms/src/IO/Endian.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@

namespace DB
{
inline constexpr bool isLittleEndian()
{
return (boost::endian::order::native == boost::endian::order::little);
}

/// Requires:
/// T is non-bool integral or scoped enumeration type
template <typename T>
Expand Down

0 comments on commit 10e188f

Please sign in to comment.