Skip to content

Commit e04d7ae

Browse files
artpaulabyss7
authored andcommitted
avoid extra allocations (ClickHouse#96)
* don't build tests by default * avoid extra allocations * fix travis * add GetTupleType Function
1 parent e1210ba commit e04d7ae

File tree

7 files changed

+23
-8
lines changed

7 files changed

+23
-8
lines changed

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,6 @@ script:
4949
- eval "${MATRIX_EVAL}"
5050
- mkdir build
5151
- cd build
52-
- cmake .. && make
52+
- cmake .. -DBUILD_TESTS=ON && make
5353
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then ./ut/clickhouse-cpp-ut ; fi
5454
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then ./ut/clickhouse-cpp-ut --gtest_filter='-Client/*' ; fi

CMakeLists.txt

+13-3
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,16 @@ INCLUDE (cmake/cpp17.cmake)
44
INCLUDE (cmake/subdirs.cmake)
55

66
OPTION(BUILD_BENCHMARK "Build benchmark" OFF)
7+
OPTION(BUILD_TESTS "Build tests" OFF)
78

89
PROJECT (CLICKHOUSE-CLIENT)
910

1011
USE_CXX17()
1112

13+
IF ("${CMAKE_BUILD_TYPE}" STREQUAL "")
14+
set(CMAKE_BUILD_TYPE "Debug")
15+
ENDIF()
16+
1217
IF (UNIX)
1318
IF (APPLE)
1419
SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2 -Wall -Wextra -Werror")
@@ -24,12 +29,17 @@ PROJECT (CLICKHOUSE-CLIENT)
2429
SUBDIRS (
2530
clickhouse
2631
contrib/cityhash
27-
contrib/gtest
2832
contrib/lz4
29-
tests/simple
30-
ut
3133
)
3234

3335
IF (BUILD_BENCHMARK)
3436
SUBDIRS(bench)
3537
ENDIF (BUILD_BENCHMARK)
38+
39+
IF (BUILD_TESTS)
40+
SUBDIRS(
41+
contrib/gtest
42+
tests/simple
43+
ut
44+
)
45+
ENDIF (BUILD_TESTS)

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ C++ client for [Yandex ClickHouse](https://clickhouse.yandex/)
2323
```sh
2424
$ mkdir build .
2525
$ cd build
26-
$ cmake ..
26+
$ cmake .. [-DBUILD_TESTS=ON]
2727
$ make
2828
```
2929

clickhouse/columns/factory.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ static ColumnRef CreateColumnFromAst(const TypeAst& ast) {
105105
case TypeAst::Tuple: {
106106
std::vector<ColumnRef> columns;
107107

108+
columns.reserve(ast.elements.size());
108109
for (const auto& elem : ast.elements) {
109110
if (auto col = CreateColumnFromAst(elem)) {
110111
columns.push_back(col);
@@ -119,6 +120,7 @@ static ColumnRef CreateColumnFromAst(const TypeAst& ast) {
119120
case TypeAst::Enum: {
120121
std::vector<Type::EnumItem> enum_items;
121122

123+
enum_items.reserve(ast.elements.size());
122124
for (const auto& elem : ast.elements) {
123125
enum_items.push_back(
124126
Type::EnumItem{elem.name, (int16_t)elem.value});

clickhouse/columns/string.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ bool ColumnFixedString::Load(CodedInputStream* input, size_t rows) {
5252
return false;
5353
}
5454

55-
data_.emplace_back(std::move(s));
55+
data_.push_back(std::move(s));
5656
}
5757

5858
return true;
@@ -122,7 +122,7 @@ bool ColumnString::Load(CodedInputStream* input, size_t rows) {
122122
return false;
123123
}
124124

125-
data_.emplace_back(std::move(s));
125+
data_.push_back(std::move(s));
126126
}
127127

128128
return true;

clickhouse/columns/uuid.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ ColumnUUID::ColumnUUID(ColumnRef data)
1515
: Column(Type::CreateUUID())
1616
, data_(data->As<ColumnUInt64>())
1717
{
18-
if (data_->Size()%2 != 0) {
18+
if (data_->Size() % 2 != 0) {
1919
throw std::runtime_error("number of entries must be even (two 64-bit numbers for each UUID)");
2020
}
2121
}

clickhouse/types/types.h

+3
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,9 @@ class TupleType : public Type {
181181

182182
std::string GetName() const;
183183

184+
/// Type of nested Tuple element type.
185+
std::vector<TypeRef> GetTupleType() const { return item_types_; }
186+
184187
private:
185188
std::vector<TypeRef> item_types_;
186189
};

0 commit comments

Comments
 (0)