diff --git a/dbms/include/DB/Functions/FunctionsCoding.h b/dbms/include/DB/Functions/FunctionsCoding.h index 3bf5dc932e3763d987c8f624a006f6741eaf2e1f..6b48d7524fad7a7b9d7a5b0638e01158bf606bab 100644 --- a/dbms/include/DB/Functions/FunctionsCoding.h +++ b/dbms/include/DB/Functions/FunctionsCoding.h @@ -573,13 +573,12 @@ public: for (size_t row = 0; row < size; ++row) { T x = vec_from[row]; - for (size_t i = 0; i < sizeof(T) * 8; ++i) + while (x) { - T bit = static_cast(1) << i; - if (x & bit) - { - res_values.push_back(bit); - } + T y = (x & (x - 1)); + T bit = x ^ y; + x = y; + res_values.push_back(bit); } res_offsets[row] = res_values.size(); } diff --git a/dbms/include/DB/Functions/FunctionsFormatting.h b/dbms/include/DB/Functions/FunctionsFormatting.h index 839487703fa81075cbc123e6a7aeb957e970ea75..8e33779eb1c26b66f0afe9c616eb000c86ea27ae 100644 --- a/dbms/include/DB/Functions/FunctionsFormatting.h +++ b/dbms/include/DB/Functions/FunctionsFormatting.h @@ -51,16 +51,15 @@ public: inline static void writeBitmask(T x, WriteBuffer & out) { bool first = true; - for (size_t i = 0; i < sizeof(T) * 8; ++i) + while (x) { - T bit = static_cast(1) << i; - if (x & bit) - { - if (!first) - out.write(",", 1); - first = false; - writeIntText(bit, out); - } + T y = (x & (x - 1)); + T bit = x ^ y; + x = y; + if (!first) + out.write(",", 1); + first = false; + writeIntText(bit, out); } }