Skip to content

use size_of from the prelude instead of std::mem::size_of #937

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/experimental/coroutines/generational_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,6 @@ impl<T> GenerationalStorage<T> {
}

pub(crate) fn allocated_memory(&self) -> usize {
self.vec.capacity() * std::mem::size_of::<GenerationalCell<T>>()
self.vec.capacity() * size_of::<GenerationalCell<T>>()
}
}
8 changes: 4 additions & 4 deletions src/experimental/scene.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,13 +300,13 @@ impl Cell {
virtual_drop: unsafe {
std::mem::transmute(&(virtual_drop::<T> as fn(*mut ())) as *const fn(*mut ()))
},
data_len: std::mem::size_of::<T>(),
data_len: size_of::<T>(),
initialized: false,
}
}

fn update<T: Node + 'static>(&mut self, data: T) {
assert!(std::mem::size_of::<T>() <= self.data_len);
assert!(size_of::<T>() <= self.data_len);

let trait_obj = &data as &dyn NodeAny;
let (_, vtable) = unsafe { std::mem::transmute::<_, (*mut (), *mut ())>(trait_obj) };
Expand Down Expand Up @@ -446,7 +446,7 @@ impl Scene {
if let Some(i) = self
.free_nodes
.iter()
.position(|free_node| free_node.data_len >= std::mem::size_of::<T>())
.position(|free_node| free_node.data_len >= size_of::<T>())
{
let mut free_node = self.free_nodes.remove(i);

Expand All @@ -459,7 +459,7 @@ impl Scene {
let trait_obj = &data as &dyn NodeAny;
let (_, vtable) = unsafe { std::mem::transmute::<_, (*mut (), *mut ())>(trait_obj) };

let ptr = self.arena.alloc(std::mem::size_of::<T>()) as *mut _ as *mut T;
let ptr = self.arena.alloc(size_of::<T>()) as *mut _ as *mut T;
unsafe {
std::ptr::write(ptr, data);
}
Expand Down
1 change: 0 additions & 1 deletion src/experimental/scene/arena.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
//! `Arena` is exported at the root of the crate.

use std::cell::Cell;
use std::mem::size_of;

const ARENA_BLOCK: usize = 64 * 1024;

Expand Down
6 changes: 3 additions & 3 deletions src/quad_gl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,12 +309,12 @@ impl PipelineExt {
let uniform_byte_size = uniform_format.size();
let uniform_byte_offset = uniform_meta.byte_offset;

if std::mem::size_of::<T>() != uniform_byte_size {
if size_of::<T>() != uniform_byte_size {
warn!(
"Trying to set uniform {} sized {} bytes value of {} bytes",
name,
uniform_byte_size,
std::mem::size_of::<T>()
size_of::<T>()
);
return;
}
Expand Down Expand Up @@ -360,7 +360,7 @@ impl PipelineExt {
"Trying to set uniform {} sized {} bytes value of {} bytes",
name,
uniform_byte_size,
std::mem::size_of::<T>()
size_of::<T>()
);
return;
}
Expand Down
11 changes: 3 additions & 8 deletions src/tobytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@ macro_rules! impl_tobytes {
impl ToBytes for $t {
fn to_bytes(&self) -> &[u8] {
unsafe {
std::slice::from_raw_parts(
self as *const _ as *const u8,
std::mem::size_of::<$t>(),
)
std::slice::from_raw_parts(self as *const _ as *const u8, size_of::<$t>())
}
}
}
Expand All @@ -27,9 +24,7 @@ impl_tobytes!(Mat4);

impl<T: ToBytes, const N: usize> ToBytes for &[T; N] {
fn to_bytes(&self) -> &[u8] {
unsafe {
std::slice::from_raw_parts(*self as *const _ as *const u8, std::mem::size_of::<T>() * N)
}
unsafe { std::slice::from_raw_parts(*self as *const _ as *const u8, size_of::<T>() * N) }
}
}

Expand All @@ -38,7 +33,7 @@ impl<T: ToBytes> ToBytes for &[T] {
unsafe {
std::slice::from_raw_parts(
self.as_ptr() as *const _ as *const u8,
std::mem::size_of::<T>() * self.len(),
size_of::<T>() * self.len(),
)
}
}
Expand Down
Loading