localcc / gvas

GVAS file format parsing library for rust
MIT License
18 stars 4 forks source link

Use std::mem::transmute() to convert Guid formats #78

Closed scottanderson closed 4 months ago

scottanderson commented 5 months ago

From experimenting with Compiler Explorer, I found std::mem::transmute() to result in the smallest machine code. The functions u128::to_le_bytes and u128::from_le_bytes do exactly this, and by replacing the tuple type (u32, u32, u32, u32) with the array type [u32; 4], we can guarantee that the compiler will not reorder the memory so that it is safe to call transmute.