提交 814b47a4 编写于 作者: M Michael Kolupaev

clickhouse: optimized bitmaskTo* functions [#CONV-6788].

上级 3cd4ad64
...@@ -573,13 +573,12 @@ public: ...@@ -573,13 +573,12 @@ public:
for (size_t row = 0; row < size; ++row) for (size_t row = 0; row < size; ++row)
{ {
T x = vec_from[row]; T x = vec_from[row];
for (size_t i = 0; i < sizeof(T) * 8; ++i) while (x)
{ {
T bit = static_cast<T>(1) << i; T y = (x & (x - 1));
if (x & bit) T bit = x ^ y;
{ x = y;
res_values.push_back(bit); res_values.push_back(bit);
}
} }
res_offsets[row] = res_values.size(); res_offsets[row] = res_values.size();
} }
......
...@@ -51,16 +51,15 @@ public: ...@@ -51,16 +51,15 @@ public:
inline static void writeBitmask(T x, WriteBuffer & out) inline static void writeBitmask(T x, WriteBuffer & out)
{ {
bool first = true; bool first = true;
for (size_t i = 0; i < sizeof(T) * 8; ++i) while (x)
{ {
T bit = static_cast<T>(1) << i; T y = (x & (x - 1));
if (x & bit) T bit = x ^ y;
{ x = y;
if (!first) if (!first)
out.write(",", 1); out.write(",", 1);
first = false; first = false;
writeIntText(bit, out); writeIntText(bit, out);
}
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册