From ef3557950c6481bed7e6bfa83bdb033e17221772 Mon Sep 17 00:00:00 2001 From: Alexey Milovidov Date: Sun, 16 Apr 2017 07:03:14 +0300 Subject: [PATCH] Less dependencies [#CLICKHOUSE-2952]. --- .../AggregateFunctions/IAggregateFunction.h | 29 ++++++++++++------ dbms/src/Common/HashTable/HashTable.h | 30 +++++++++---------- dbms/src/Common/HashTable/SmallTable.h | 2 +- 3 files changed, 36 insertions(+), 25 deletions(-) diff --git a/dbms/src/AggregateFunctions/IAggregateFunction.h b/dbms/src/AggregateFunctions/IAggregateFunction.h index 6f75690a0ae..895844c1b7f 100644 --- a/dbms/src/AggregateFunctions/IAggregateFunction.h +++ b/dbms/src/AggregateFunctions/IAggregateFunction.h @@ -1,16 +1,30 @@ #pragma once +#include #include +#include +#include -#include -#include -#include -#include +#include +#include +#include namespace DB { +class Arena; +class ReadBuffer; +class WriteBuffer; +class IColumn; +class IDataType; + +using DataTypePtr = std::shared_ptr; +using DataTypes = std::vector; + +using AggregateDataPtr = char *; +using ConstAggregateDataPtr = const char *; + namespace ErrorCodes { extern const int AGGREGATE_FUNCTION_DOESNT_ALLOW_PARAMETERS; @@ -19,9 +33,6 @@ namespace ErrorCodes extern const int ARGUMENT_OUT_OF_BOUND; } -using AggregateDataPtr = char *; -using ConstAggregateDataPtr = const char *; - /** Aggregate functions interface. * Instances of classes with this interface do not contain the data itself for aggregation, @@ -142,7 +153,7 @@ public: bool hasTrivialDestructor() const override { - return __has_trivial_destructor(Data); + return std::is_trivially_destructible::value; } size_t sizeOfData() const override @@ -153,7 +164,7 @@ public: /// NOTE: Currently not used (structures with aggregation state are put without alignment). size_t alignOfData() const override { - return __alignof__(Data); + return alignof(Data); } }; diff --git a/dbms/src/Common/HashTable/HashTable.h b/dbms/src/Common/HashTable/HashTable.h index 54044801316..50ffb4058b2 100644 --- a/dbms/src/Common/HashTable/HashTable.h +++ b/dbms/src/Common/HashTable/HashTable.h @@ -98,11 +98,11 @@ struct HashTableCell /// HashTableCell(const value_type & value_, const State & state) : key(value_) {} /// Получить то, что будет value_type контейнера. - value_type & getValue() { return key; } + value_type & getValue() { return key; } const value_type & getValue() const { return key; } /// Получить ключ. - static Key & getKey(value_type & value) { return value; } + static Key & getKey(value_type & value) { return value; } static const Key & getKey(const value_type & value) { return value; } /// Равны ли ключи у ячеек. @@ -155,10 +155,10 @@ struct HashTableGrower UInt8 size_degree = initial_size_degree; /// Размер хэш-таблицы в ячейках. - size_t bufSize() const { return 1 << size_degree; } + size_t bufSize() const { return 1 << size_degree; } - size_t maxFill() const { return 1 << (size_degree - 1); } - size_t mask() const { return bufSize() - 1; } + size_t maxFill() const { return 1 << (size_degree - 1); } + size_t mask() const { return bufSize() - 1; } /// Из значения хэш-функции получить номер ячейки в хэш-таблице. size_t place(size_t x) const { return x & mask(); } @@ -200,7 +200,7 @@ struct HashTableGrower template struct HashTableFixedGrower { - size_t bufSize() const { return 1 << key_bits; } + size_t bufSize() const { return 1 << key_bits; } size_t place(size_t x) const { return x; } /// Тут можно было бы написать __builtin_unreachable(), но компилятор не до конца всё оптимизирует, и получается менее эффективно. size_t next(size_t pos) const { return pos + 1; } @@ -221,15 +221,15 @@ struct ZeroValueStorage { private: bool has_zero = false; - char zero_value_storage[sizeof(Cell)] __attribute__((__aligned__(__alignof__(Cell)))); /// Кусок памяти для элемента с ключём 0. + typename std::aligned_storage::type zero_value_storage; /// Storage of element with zero key. public: bool hasZero() const { return has_zero; } void setHasZero() { has_zero = true; } void clearHasZero() { has_zero = false; } - Cell * zeroValue() { return reinterpret_cast(zero_value_storage); } - const Cell * zeroValue() const { return reinterpret_cast(zero_value_storage); } + Cell * zeroValue() { return reinterpret_cast(&zero_value_storage); } + const Cell * zeroValue() const { return reinterpret_cast(&zero_value_storage); } }; template @@ -240,7 +240,7 @@ struct ZeroValueStorage void clearHasZero() {} Cell * zeroValue() { return nullptr; } - const Cell * zeroValue() const { return nullptr; } + const Cell * zeroValue() const { return nullptr; } }; @@ -416,7 +416,7 @@ protected: void destroyElements() { - if (!__has_trivial_destructor(Cell)) + if (!std::is_trivially_destructible::value) for (iterator it = begin(); it != end(); ++it) it.ptr->~Cell(); } @@ -605,10 +605,10 @@ public: protected: - const_iterator iteratorTo(const Cell * ptr) const { return const_iterator(this, ptr); } - iterator iteratorTo(Cell * ptr) { return iterator(this, ptr); } - const_iterator iteratorToZero() const { return iteratorTo(this->zeroValue()); } - iterator iteratorToZero() { return iteratorTo(this->zeroValue()); } + const_iterator iteratorTo(const Cell * ptr) const { return const_iterator(this, ptr); } + iterator iteratorTo(Cell * ptr) { return iterator(this, ptr); } + const_iterator iteratorToZero() const { return iteratorTo(this->zeroValue()); } + iterator iteratorToZero() { return iteratorTo(this->zeroValue()); } /// Если ключ нулевой - вставить его в специальное место и вернуть true. diff --git a/dbms/src/Common/HashTable/SmallTable.h b/dbms/src/Common/HashTable/SmallTable.h index 39436947d41..413adac0018 100644 --- a/dbms/src/Common/HashTable/SmallTable.h +++ b/dbms/src/Common/HashTable/SmallTable.h @@ -348,7 +348,7 @@ public: void clear() { - if (!__has_trivial_destructor(Cell)) + if (!std::is_trivially_destructible::value) for (iterator it = begin(); it != end(); ++it) it.ptr->~Cell();