Casting a U8 pointer to a wider pointer may result in an unaligned address, which can apparently cause performance issues and/or signals on some platforms, and is generally thought to be bad practice.
We can avoid this by casting in the opposite direction instead (wider type to U8) and use memcpy, which will be well-optimized by LLVM and will also safely handle unaligned addresses appropriately.
This is apparently faster than the more obvious trick of getting the bytes one-by-one and bit-shifting them to combine them.
Casting a U8 pointer to a wider pointer may result in an unaligned address, which can apparently cause performance issues and/or signals on some platforms, and is generally thought to be bad practice.
We can avoid this by casting in the opposite direction instead (wider type to U8) and use
memcpy
, which will be well-optimized by LLVM and will also safely handle unaligned addresses appropriately.This is apparently faster than the more obvious trick of getting the bytes one-by-one and bit-shifting them to combine them.