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.