Skip to content

Commit

Permalink
chore: replace debug_Assert with assert
Browse files Browse the repository at this point in the history
  • Loading branch information
joamag committed Jun 18, 2024
1 parent 5d04234 commit 97925b8
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ pub fn save_bmp(path: &str, pixels: &[u8], width: u32, height: u32) -> Result<()
/// This function is optimized for performance and uses pointer-based
/// operations to copy the data as fast as possible.
pub fn copy_fast(src: &[u8], dst: &mut [u8], count: usize) {
debug_assert!(src.len() >= count);
debug_assert!(dst.len() >= count);
assert!(src.len() >= count);

This comment has been minimized.

Copy link
@itytophile

itytophile Jun 18, 2024

Contributor

Hi, sorry to bother but instead of using assert!, you can use the safe counterpart copy_from_slice https://doc.rust-lang.org/std/primitive.slice.html#method.copy_from_slice

It does the same thing as your code i. e. bound checking and ptr::copy_nonoverlapping

This comment has been minimized.

Copy link
@joamag

joamag Jun 18, 2024

Author Owner

You're right; this is probably (performance-wise) equivalent to copy_from_slice πŸ˜…

assert!(dst.len() >= count);

unsafe {
let src_ptr = src.as_ptr();
Expand Down

0 comments on commit 97925b8

Please sign in to comment.