From 3d201c37c05a488d444ca3eff274260892f0b345 Mon Sep 17 00:00:00 2001 From: Nikita Mikhaylov Date: Mon, 9 Aug 2021 15:42:29 +0000 Subject: [PATCH] Done --- src/Core/Block.cpp | 14 ++++++++++++++ src/Core/Block.h | 1 + 2 files changed, 15 insertions(+) diff --git a/src/Core/Block.cpp b/src/Core/Block.cpp index efd8de43a3c..96667862e41 100644 --- a/src/Core/Block.cpp +++ b/src/Core/Block.cpp @@ -44,6 +44,13 @@ void Block::initializeIndexByName() } +void Block::reserve(size_t count) +{ + index_by_name.reserve(count); + data.reserve(count); +} + + void Block::insert(size_t position, ColumnWithTypeAndName elem) { if (position > data.size()) @@ -287,6 +294,7 @@ std::string Block::dumpIndex() const Block Block::cloneEmpty() const { Block res; + res.reserve(data.size()); for (const auto & elem : data) res.insert(elem.cloneEmpty()); @@ -364,6 +372,8 @@ Block Block::cloneWithColumns(MutableColumns && columns) const Block res; size_t num_columns = data.size(); + res.reserve(num_columns); + for (size_t i = 0; i < num_columns; ++i) res.insert({ std::move(columns[i]), data[i].type, data[i].name }); @@ -381,6 +391,8 @@ Block Block::cloneWithColumns(const Columns & columns) const throw Exception("Cannot clone block with columns because block has " + toString(num_columns) + " columns, " "but " + toString(columns.size()) + " columns given.", ErrorCodes::LOGICAL_ERROR); + res.reserve(num_columns); + for (size_t i = 0; i < num_columns; ++i) res.insert({ columns[i], data[i].type, data[i].name }); @@ -393,6 +405,8 @@ Block Block::cloneWithoutColumns() const Block res; size_t num_columns = data.size(); + res.reserve(num_columns); + for (size_t i = 0; i < num_columns; ++i) res.insert({ nullptr, data[i].type, data[i].name }); diff --git a/src/Core/Block.h b/src/Core/Block.h index a2d91190795..14f82cecd8d 100644 --- a/src/Core/Block.h +++ b/src/Core/Block.h @@ -152,6 +152,7 @@ public: private: void eraseImpl(size_t position); void initializeIndexByName(); + void reserve(size_t count); /// This is needed to allow function execution over data. /// It is safe because functions does not change column names, so index is unaffected.