[libcxx-commits] [PATCH] D74290: [libcxx] Qualify make_move_iterator in vector::insert for input iterators
Logan Smith via Phabricator via libcxx-commits
libcxx-commits at lists.llvm.org
Sun Feb 9 18:00:26 PST 2020
logan-5 added a comment.
In D74290#1865949 <https://reviews.llvm.org/D74290#1865949>, @Quuxplusone wrote:
> I don't understand the actual algorithm being used in `insert`-with-input-iterators
Seems reasonable enough to me:
1. insert up to capacity at the end of the vector
2. construct any additional elements that would overflow capacity in a scratch buffer, then see how big it is (because input iterators), and reserve new capacity (if exception is thrown, destroy items from step 1--easy since they're still sitting at the end)
3. rotate items from step 1 into place, and then insert() the scratch buffer after those
I'm not sure why you'd insert() the scratch buffer instead of just moving its elements onto the vector's end and then rotating all the elements into place at once, but maybe the insert() overload called for the scratch buffer does things more efficiently somehow.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D74290/new/
https://reviews.llvm.org/D74290
More information about the libcxx-commits
mailing list