mirror of
https://github.com/gfx-rs/wgpu.git
synced 2024-11-25 16:24:24 +00:00
refactor: satisfy clippy::manual_slice_size_calculation
This commit is contained in:
parent
adc43b5672
commit
2492956014
@ -12,9 +12,9 @@ use winit::{
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn cast_slice<T>(data: &[T]) -> &[u8] {
|
||||
use std::{mem::size_of, slice::from_raw_parts};
|
||||
use std::{mem::size_of_val, slice::from_raw_parts};
|
||||
|
||||
unsafe { from_raw_parts(data.as_ptr() as *const u8, data.len() * size_of::<T>()) }
|
||||
unsafe { from_raw_parts(data.as_ptr() as *const u8, size_of_val(data)) }
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
|
@ -75,8 +75,7 @@ async fn execute_gpu_inner(
|
||||
});
|
||||
|
||||
// Gets the size in bytes of the buffer.
|
||||
let slice_size = numbers.len() * std::mem::size_of::<u32>();
|
||||
let size = slice_size as wgpu::BufferAddress;
|
||||
let size = std::mem::size_of_val(numbers) as wgpu::BufferAddress;
|
||||
|
||||
// Instantiates buffer without data.
|
||||
// `usage` of buffer specifies how it can be used:
|
||||
|
@ -49,10 +49,7 @@ impl super::CommandBuffer {
|
||||
|
||||
fn add_push_constant_data(&mut self, data: &[u32]) -> Range<u32> {
|
||||
let data_raw = unsafe {
|
||||
std::slice::from_raw_parts(
|
||||
data.as_ptr() as *const _,
|
||||
data.len() * mem::size_of::<u32>(),
|
||||
)
|
||||
std::slice::from_raw_parts(data.as_ptr() as *const _, mem::size_of_val(data))
|
||||
};
|
||||
let start = self.data_bytes.len();
|
||||
assert!(start < u32::MAX as usize);
|
||||
|
Loading…
Reference in New Issue
Block a user