Add load/store_unchecked to ByteAddressableBuffer without bounds check (#746)

This commit is contained in:
Ashley Hauck 2021-09-03 14:10:01 +02:00 committed by GitHub
parent 71d6001bed
commit 95da8981ad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -50,6 +50,18 @@ impl<'a> ByteAddressableBuffer<'a> {
buffer_load_intrinsic(self.data, byte_index)
}
/// Loads an arbitrary type from the buffer. `byte_index` must be a multiple of 4, otherwise,
/// it will get silently rounded down to the nearest multiple of 4. Bounds checking is not
/// performed.
///
/// # Safety
/// This function allows writing a type to an untyped buffer, then reading a different type
/// from the same buffer, allowing all sorts of safety guarantees to be bypassed (effectively a
/// transmute). Additionally, bounds checking is not performed.
pub unsafe fn load_unchecked<T>(self, byte_index: u32) -> T {
buffer_load_intrinsic(self.data, byte_index)
}
/// Stores an arbitrary type int the buffer. `byte_index` must be a multiple of 4, otherwise,
/// it will get silently rounded down to the nearest multiple of 4.
///
@ -63,4 +75,16 @@ impl<'a> ByteAddressableBuffer<'a> {
}
buffer_store_intrinsic(self.data, byte_index, value);
}
/// Stores an arbitrary type int the buffer. `byte_index` must be a multiple of 4, otherwise,
/// it will get silently rounded down to the nearest multiple of 4. Bounds checking is not
/// performed.
///
/// # Safety
/// This function allows writing a type to an untyped buffer, then reading a different type
/// from the same buffer, allowing all sorts of safety guarantees to be bypassed (effectively a
/// transmute). Additionally, bounds checking is not performed.
pub unsafe fn store_unchecked<T>(self, byte_index: u32, value: T) {
buffer_store_intrinsic(self.data, byte_index, value);
}
}