Merge pull request #26620 from ClickHouse/more-cpp

Remove some code, more C++ way
This commit is contained in:
alexey-milovidov 2021-07-21 15:23:19 +03:00 committed by GitHub
commit 66d3b534a6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 37 deletions

View File

@ -44,21 +44,7 @@ void Block::initializeIndexByName()
}
void Block::insert(size_t position, const ColumnWithTypeAndName & elem)
{
if (position > data.size())
throw Exception("Position out of bound in Block::insert(), max position = "
+ toString(data.size()), ErrorCodes::POSITION_OUT_OF_BOUND);
for (auto & name_pos : index_by_name)
if (name_pos.second >= position)
++name_pos.second;
index_by_name.emplace(elem.name, position);
data.emplace(data.begin() + position, elem);
}
void Block::insert(size_t position, ColumnWithTypeAndName && elem)
void Block::insert(size_t position, ColumnWithTypeAndName elem)
{
if (position > data.size())
throw Exception("Position out of bound in Block::insert(), max position = "
@ -73,26 +59,14 @@ void Block::insert(size_t position, ColumnWithTypeAndName && elem)
}
void Block::insert(const ColumnWithTypeAndName & elem)
{
index_by_name.emplace(elem.name, data.size());
data.emplace_back(elem);
}
void Block::insert(ColumnWithTypeAndName && elem)
void Block::insert(ColumnWithTypeAndName elem)
{
index_by_name.emplace(elem.name, data.size());
data.emplace_back(std::move(elem));
}
void Block::insertUnique(const ColumnWithTypeAndName & elem)
{
if (index_by_name.end() == index_by_name.find(elem.name))
insert(elem);
}
void Block::insertUnique(ColumnWithTypeAndName && elem)
void Block::insertUnique(ColumnWithTypeAndName elem)
{
if (index_by_name.end() == index_by_name.find(elem.name))
insert(std::move(elem));
@ -369,7 +343,7 @@ void Block::setColumns(const Columns & columns)
}
void Block::setColumn(size_t position, ColumnWithTypeAndName && column)
void Block::setColumn(size_t position, ColumnWithTypeAndName column)
{
if (position >= data.size())
throw Exception(ErrorCodes::POSITION_OUT_OF_BOUND, "Position {} out of bound in Block::setColumn(), max position {}",

View File

@ -39,14 +39,11 @@ public:
Block(const ColumnsWithTypeAndName & data_);
/// insert the column at the specified position
void insert(size_t position, const ColumnWithTypeAndName & elem);
void insert(size_t position, ColumnWithTypeAndName && elem);
void insert(size_t position, ColumnWithTypeAndName elem);
/// insert the column to the end
void insert(const ColumnWithTypeAndName & elem);
void insert(ColumnWithTypeAndName && elem);
void insert(ColumnWithTypeAndName elem);
/// insert the column to the end, if there is no column with that name yet
void insertUnique(const ColumnWithTypeAndName & elem);
void insertUnique(ColumnWithTypeAndName && elem);
void insertUnique(ColumnWithTypeAndName elem);
/// remove the column at the specified position
void erase(size_t position);
/// remove the columns at the specified positions
@ -125,7 +122,7 @@ public:
Columns getColumns() const;
void setColumns(const Columns & columns);
void setColumn(size_t position, ColumnWithTypeAndName && column);
void setColumn(size_t position, ColumnWithTypeAndName column);
Block cloneWithColumns(const Columns & columns) const;
Block cloneWithoutColumns() const;
Block cloneWithCutColumns(size_t start, size_t length) const;