mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-22 15:42:02 +00:00
Sort iterators to avoid extra std::string creation in Block::sortColumns()
Since std::string is pretty heavy. Suggested-by: @alexey-milovidov
This commit is contained in:
parent
0e117abd2b
commit
4de7d7a84f
@ -404,13 +404,18 @@ Block Block::sortColumns() const
|
||||
Block sorted_block;
|
||||
|
||||
/// std::unordered_map (index_by_name) cannot be used to guarantee the sort order
|
||||
std::vector<std::pair<String, size_t>> sorted_index_by_name(index_by_name.begin(), index_by_name.end());
|
||||
std::vector<decltype(index_by_name.begin())> sorted_index_by_name(index_by_name.size());
|
||||
{
|
||||
size_t i = 0;
|
||||
for (auto it = index_by_name.begin(); it != index_by_name.end(); ++it)
|
||||
sorted_index_by_name[i++] = it;
|
||||
}
|
||||
std::sort(sorted_index_by_name.begin(), sorted_index_by_name.end(), [](const auto & lhs, const auto & rhs) {
|
||||
return lhs.first < rhs.first;
|
||||
return lhs->first < rhs->first;
|
||||
});
|
||||
|
||||
for (const auto & name : sorted_index_by_name)
|
||||
sorted_block.insert(data[name.second]);
|
||||
for (const auto & it : sorted_index_by_name)
|
||||
sorted_block.insert(data[it->second]);
|
||||
|
||||
return sorted_block;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user