C++: optimize SharedVector's iterator constructor

Don't detach for every element.

Closes #2737
This commit is contained in:
Olivier Goffart 2023-05-16 19:21:46 +02:00 committed by Olivier Goffart
parent adcb55fd18
commit 422bcc3a4a
2 changed files with 6 additions and 3 deletions

View file

@ -60,9 +60,8 @@ struct SharedVector
SharedVector(InputIt first, InputIt last)
: SharedVector(SharedVector::with_capacity(std::distance(first, last)))
{
for (auto it = first; it != last; ++it) {
push_back(*it);
}
std::uninitialized_copy(first, last, begin());
inner->size = inner->capacity;
}
/// Creates a new vector that is a copy of \a other.

View file

@ -237,4 +237,8 @@ TEST_CASE("SharedVector")
SharedVector<int> vec4(5);
REQUIRE(vec4.size() == 5);
REQUIRE(vec4[3] == 0);
std::vector<SharedString> std_v(vec2.begin(), vec2.end());
SharedVector<SharedString> vec6(std_v.begin(), std_v.end());
REQUIRE(vec6 == vec2);
}