Remove unnecessary copy

This commit is contained in:
Robin Dietzel 2023-12-05 10:53:51 +01:00
parent f7d12edd60
commit e732d062b6

View File

@ -20,13 +20,11 @@ public:
private:
auto parition(std::span<T> &data) -> std::pair<std::span<T>, std::span<T>> {
std::vector<T> buf(data);
auto pivot = data.begin();
std::advance(pivot, std::distance(data.begin(), data.end()) / 2);
auto pivot = buf.begin();
std::advance(pivot, std::distance(buf.begin(), buf.end()) / 2);
auto lefti = buf.begin();
auto righti = buf.end();
auto lefti = data.begin();
auto righti = data.end();
while (1) {
for (; cmp(*lefti, *pivot); lefti++);
@ -39,7 +37,6 @@ private:
std::swap(lefti, righti);
}
std::move(buf.begin(), buf.end(), data.begin());
return {std::span<T>(data.begin(), lefti), std::span<T>(lefti, data.end())};
}