We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 20673db commit d7425d3Copy full SHA for d7425d3
crates/bevy_core/src/bytes.rs
@@ -49,11 +49,7 @@ where
49
T: Byteable + Clone,
50
{
51
fn from_bytes(bytes: &[u8]) -> Self {
52
- unsafe {
53
- let byte_ptr = bytes.as_ptr();
54
- let ptr = byte_ptr as *const Self;
55
- (*ptr).clone()
56
- }
+ unsafe { bytes.as_ptr().cast::<Self>().read_unaligned() }
57
}
58
59
@@ -170,10 +166,8 @@ where
170
166
171
167
172
168
unsafe {
173
- let byte_ptr = bytes.as_ptr() as *const T;
174
- let len = bytes.len() / std::mem::size_of::<T>();
175
- let slice = core::slice::from_raw_parts::<T>(byte_ptr, len);
176
- slice.to_vec()
169
+ let (_, body, _) = bytes.align_to::<T>();
+ body.to_vec()
177
178
179
0 commit comments