Faster ColumnVector::replicate()

This commit is contained in:
Alexander Kazakov 2020-02-21 22:47:20 +03:00
parent 2e8dd9d9fc
commit 1c86a31431

View File

@ -346,18 +346,14 @@ ColumnPtr ColumnVector<T>::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;