PR #1968: Use std::move_backward within InlinedVector's Storage::Insert Imported from GitHub PR https://github.com/abseil/abseil-cpp/pull/1968 Both libc++ and libstdc++ have optimizations within `std::move_backward` that support lowering to `memmove` when it is appropriate for the types involved. Using it significantly speeds up insert on vectors of trivial types such as integers. This completely addresses the [poor insert performance relative to other inline capacity vectors](https://github.com/martinus/svector#random-insert) that others have observed. See also https://github.com/abseil/abseil-cpp/discussions/1934. Merge 8ce6a5e699407321d2d229ca359f255463b05285 into 7374f9b0f4275df2e939f1aacbd323ad0182b897 Merging this change closes #1968 COPYBARA_INTEGRATE_REVIEW=https://github.com/abseil/abseil-cpp/pull/1968 from bdash:inlinedvector-insert-move 8ce6a5e699407321d2d229ca359f255463b05285 PiperOrigin-RevId: 828597732 Change-Id: Ica73f189f3fd5385ee90b532964ddf476d3fa223
diff --git a/absl/container/internal/inlined_vector.h b/absl/container/internal/inlined_vector.h index 85e8960..c7b709f 100644 --- a/absl/container/internal/inlined_vector.h +++ b/absl/container/internal/inlined_vector.h
@@ -795,16 +795,9 @@ move_construction_values, move_construction.size()); - for (Pointer<A> - destination = move_assignment.data() + move_assignment.size(), - last_destination = move_assignment.data(), - source = move_assignment_values + move_assignment.size(); - ;) { - --destination; - --source; - if (destination < last_destination) break; - *destination = std::move(*source); - } + std::move_backward(move_assignment_values, + move_assignment_values + move_assignment.size(), + move_assignment.data() + move_assignment.size()); AssignElements<A>(insert_assignment.data(), values, insert_assignment.size());