Avoid calling memcpy
in swap
by AlexGuteniev · Pull Request #5500 · microsoft/STL (original) (raw)
Fixes #5481
The release codegen is the same, the benchmark results are the same.
memcpy
calls are now not emitted in any mode. In /Od
we have rep movsb
, which is pretty good for a debug mode.
unsigned char
is kept for underlying type as it doesn't have alignment requirements, and also is a valid alias for any object.
@frederick-vs-ja pointed out that the strict aliasing rule is still violated here. I excluded Clang (and thus Intel), I verified Clang already optimizes the usual swap loop on its own. MSVC doesn't take advantage of strict aliasing, so it is fine 🔥🐶☕🔥