diff --git a/dbms/src/Columns/ColumnVector.cpp b/dbms/src/Columns/ColumnVector.cpp index 1e275f4ec13..99f9d1b91e4 100644 --- a/dbms/src/Columns/ColumnVector.cpp +++ b/dbms/src/Columns/ColumnVector.cpp @@ -346,18 +346,14 @@ ColumnPtr ColumnVector::replicate(const IColumn::Offsets & offsets) const if (0 == size) return this->create(); - auto res = this->create(); - typename Self::Container & res_data = res->getData(); - res_data.reserve(offsets.back()); + auto res = this->create(offsets.back()); - IColumn::Offset prev_offset = 0; + auto it = res->getData().begin(); for (size_t i = 0; i < size; ++i) { - size_t size_to_replicate = offsets[i] - prev_offset; - prev_offset = offsets[i]; - - for (size_t j = 0; j < size_to_replicate; ++j) - res_data.push_back(data[i]); + const auto span_end = res->getData().begin() + offsets[i]; + for (; it < span_end; ++it) + *it = data[i]; } return res;