[PATCH] D22725: [clang-tidy] Add check 'misc-replace-memcpy'

Piotr Padlewski via cfe-commits cfe-commits at lists.llvm.org
Sat Jul 23 10:40:51 PDT 2016


Prazek added a comment.

In https://reviews.llvm.org/D22725#493942, @JDevlieghere wrote:

> In https://reviews.llvm.org/D22725#493940, @aaron.ballman wrote:
>
> > > Using std::copy opens up the possibility of type-aware optimizations which are not possible with memcpy.
> >
> >
> > To my knowledge, those type-aware optimizations are for transforming copies involving trivially-copyable types into calls to memcpy(). What other optimizations does this check enable?
>
>
> I might be mistaken, but I understood that a call to std::copy (whether or not specialized for certain types) might get inlined, while a call to memcpy is typically not.


So if it is something trivially copyable (just copying bytes) then std::copy would probably call memcpy inside - so it won't be optimization in our case (even if it will get inlined).

But it will definitelly make code cleaner and won't be slower, which would be good to mention in docs.


Repository:
  rL LLVM

https://reviews.llvm.org/D22725





More information about the cfe-commits mailing list