[libcxx-commits] [PATCH] D124328: [libc++] Forward more often to memmove in copy

Nikolas Klauser via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Thu Apr 28 07:39:47 PDT 2022

philnik added a comment.

In D124328#3479081 <https://reviews.llvm.org/D124328#3479081>, @var-const wrote:

> Is it possible to add some tests for this? For checking the optimization, perhaps use structs containing pointers to dynamically-allocated memory that have deep-copying constructors, then check that only the pointers themselves were copied?

I don't think there is a way to check other than grepping for `memmove` in the binary. IIUC you suggestion would be to add non-trivial assignment operators, but that would disable the optimization. The optimization should only apply if it's invisible to the user.

Comment at: libcxx/include/__algorithm/copy.h:105
+pair<reverse_iterator<reverse_iterator<_InIter> >, reverse_iterator<reverse_iterator<_OutIter> > >
+__copy_impl(reverse_iterator<reverse_iterator<_InIter>> __first,
+            reverse_iterator<reverse_iterator<_Sent>> __last,
var-const wrote:
> Question: why wouldn't the other `reverse_iter` overload that calls `__unwrap_iter` handle the case?
With a `reverse_iterator<reverse_iterator<int*>>` the other overload would have `_InIter = reverse_iterator<int*>`. This is only a random access iterator and not a contiguous iterator, so it wouldn't get unwrapped.

  rG LLVM Github Monorepo



More information about the libcxx-commits mailing list