mirror of
https://github.com/slint-ui/slint.git
synced 2025-08-04 18:58:36 +00:00
C++: optimize SharedVector's iterator constructor
Don't detach for every element. Closes #2737
This commit is contained in:
parent
adcb55fd18
commit
422bcc3a4a
2 changed files with 6 additions and 3 deletions
|
@ -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.
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue