From 1a37afa3d12b58845b9476c2cf762710140a5009 Mon Sep 17 00:00:00 2001 From: Nikolai Kochetov Date: Wed, 25 Mar 2020 14:14:11 +0300 Subject: [PATCH] Review fixes. --- dbms/src/Columns/ColumnAggregateFunction.cpp | 2 +- dbms/src/Columns/ColumnDecimal.cpp | 4 ++-- dbms/src/Columns/ColumnFixedString.cpp | 4 ++-- dbms/src/Columns/ColumnString.cpp | 7 ++++--- dbms/src/Columns/ColumnVector.cpp | 4 ++-- dbms/src/Common/HashTable/Hash.h | 6 +++--- 6 files changed, 14 insertions(+), 13 deletions(-) diff --git a/dbms/src/Columns/ColumnAggregateFunction.cpp b/dbms/src/Columns/ColumnAggregateFunction.cpp index de7a3b22dec..474dd418186 100644 --- a/dbms/src/Columns/ColumnAggregateFunction.cpp +++ b/dbms/src/Columns/ColumnAggregateFunction.cpp @@ -293,9 +293,9 @@ void ColumnAggregateFunction::updateWeakHash32(WeakHash32 & hash) const auto & hash_data = hash.getData(); + std::vector v; for (size_t i = 0; i < s; ++i) { - std::vector v; WriteBufferFromVector> wbuf(v); func->serialize(data[i], wbuf); wbuf.finalize(); diff --git a/dbms/src/Columns/ColumnDecimal.cpp b/dbms/src/Columns/ColumnDecimal.cpp index c82b664ac06..511ed7c1a8b 100644 --- a/dbms/src/Columns/ColumnDecimal.cpp +++ b/dbms/src/Columns/ColumnDecimal.cpp @@ -77,9 +77,9 @@ void ColumnDecimal::updateWeakHash32(WeakHash32 & hash) const throw Exception("Size of WeakHash32 does not match size of column: column size is " + std::to_string(s) + ", hash size is " + std::to_string(hash.getData().size()), ErrorCodes::LOGICAL_ERROR); - const T * begin = &data[0]; + const T * begin = data.data(); const T * end = begin + s; - UInt32 * hash_data = &hash.getData()[0]; + UInt32 * hash_data = hash.getData().data(); while (begin < end) { diff --git a/dbms/src/Columns/ColumnFixedString.cpp b/dbms/src/Columns/ColumnFixedString.cpp index d60c487eca9..b66ff5370b0 100644 --- a/dbms/src/Columns/ColumnFixedString.cpp +++ b/dbms/src/Columns/ColumnFixedString.cpp @@ -112,8 +112,8 @@ void ColumnFixedString::updateWeakHash32(WeakHash32 & hash) const throw Exception("Size of WeakHash32 does not match size of column: column size is " + std::to_string(s) + ", hash size is " + std::to_string(hash.getData().size()), ErrorCodes::LOGICAL_ERROR); - const UInt8 * pos = &chars[0]; - UInt32 * hash_data = &hash.getData()[0]; + const UInt8 * pos = chars.data(); + UInt32 * hash_data = hash.getData().data(); for (size_t row = 0; row < s; ++row) { diff --git a/dbms/src/Columns/ColumnString.cpp b/dbms/src/Columns/ColumnString.cpp index dbf90b02f57..84757c776ba 100644 --- a/dbms/src/Columns/ColumnString.cpp +++ b/dbms/src/Columns/ColumnString.cpp @@ -74,14 +74,15 @@ void ColumnString::updateWeakHash32(WeakHash32 & hash) const throw Exception("Size of WeakHash32 does not match size of column: column size is " + std::to_string(s) + ", hash size is " + std::to_string(hash.getData().size()), ErrorCodes::LOGICAL_ERROR); - const UInt8 * pos = &chars[0]; - UInt32 * hash_data = &hash.getData()[0]; + const UInt8 * pos = chars.data(); + UInt32 * hash_data = hash.getData().data(); Offset prev_offset = 0; for (auto & offset : offsets) { auto str_size = offset - prev_offset; - *hash_data = ::updateWeakHash32(pos, str_size, *hash_data); + /// Skip last zero byte. + *hash_data = ::updateWeakHash32(pos, str_size - 1, *hash_data); pos += str_size; prev_offset = offset; diff --git a/dbms/src/Columns/ColumnVector.cpp b/dbms/src/Columns/ColumnVector.cpp index f5661fd53ec..b5634a5814c 100644 --- a/dbms/src/Columns/ColumnVector.cpp +++ b/dbms/src/Columns/ColumnVector.cpp @@ -63,9 +63,9 @@ void ColumnVector::updateWeakHash32(WeakHash32 & hash) const throw Exception("Size of WeakHash32 does not match size of column: column size is " + std::to_string(s) + ", hash size is " + std::to_string(hash.getData().size()), ErrorCodes::LOGICAL_ERROR); - const T * begin = &data[0]; + const T * begin = data.data(); const T * end = begin + s; - UInt32 * hash_data = &hash.getData()[0]; + UInt32 * hash_data = hash.getData().data(); while (begin < end) { diff --git a/dbms/src/Common/HashTable/Hash.h b/dbms/src/Common/HashTable/Hash.h index 2437f6b86cc..cdaf5baa752 100644 --- a/dbms/src/Common/HashTable/Hash.h +++ b/dbms/src/Common/HashTable/Hash.h @@ -75,11 +75,11 @@ template inline typename std::enable_if<(sizeof(T) > sizeof(DB::UInt64)), DB::UInt64>::type intHashCRC32(const T & x, DB::UInt64 updated_value) { - auto * begin64 = reinterpret_cast(&x); + auto * begin = reinterpret_cast(&x); for (size_t i = 0; i < sizeof(T); i += sizeof(UInt64)) { - updated_value = intHashCRC32(*begin64, updated_value); - ++begin64; + updated_value = intHashCRC32(unalignedLoad(begin), updated_value); + begin += sizeof(DB::UInt64); } return updated_value;