From bfe2a1967138afdabe04684dacaf5bc7b87231e4 Mon Sep 17 00:00:00 2001 From: Ryan Jones-Ward Date: Mon, 20 Jan 2025 15:44:02 +0000 Subject: [PATCH] Switch some asserts to debug asserts, since they can't occur in practice. --- psistega3-cli/src/main.rs | 19 +++++++++++++++++++ psistega3-core/src/codecs/v1.rs | 6 +++--- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/psistega3-cli/src/main.rs b/psistega3-cli/src/main.rs index 58fd598..22784a6 100644 --- a/psistega3-cli/src/main.rs +++ b/psistega3-cli/src/main.rs @@ -25,6 +25,25 @@ enum ActionType { fn main() { SimpleLogger::new().init().unwrap(); + use std::time::Instant; + let now = Instant::now(); + + { + for _ in 0..50 { + let mut s = StegaV1::new("aaaa"); + let _ = s.encode( + "D:\\Pictures\\Jeff's Wallpapers\\RJ 1.png", + "aaaaaa".to_string(), + "aaaaaaaaaa", + "D:\\Temp\\output.png", + ); + } + } + + let elapsed = now.elapsed(); + println!("Elapsed: {:.2?}", elapsed / 50); + return; + let mut args: Vec = env::args().collect(); if args.len() == 1 { show_help(); diff --git a/psistega3-core/src/codecs/v1.rs b/psistega3-core/src/codecs/v1.rs index 3a5f320..32dc714 100644 --- a/psistega3-core/src/codecs/v1.rs +++ b/psistega3-core/src/codecs/v1.rs @@ -951,7 +951,7 @@ impl DataDecoder { /// Pop a XOR-decoded byte from the front of the byte list. /// pub fn pop_u8(&mut self) -> u8 { - assert!(!self.bytes.is_empty(), "insufficient values available"); + debug_assert!(!self.bytes.is_empty(), "insufficient values available"); // We do not need to worry about decoding these values from little // Endian because that will have been done when loading the values. @@ -965,7 +965,7 @@ impl DataDecoder { /// `Note:` this method will automatically convert the returned value from little Endian to the correct bit-format. /// pub fn pop_u32(&mut self) -> u32 { - assert!(self.bytes.len() >= 4, "insufficient values available"); + debug_assert!(self.bytes.len() >= 4, "insufficient values available"); let mut bytes = [0u8; 4]; bytes.iter_mut().for_each(|i| { @@ -980,7 +980,7 @@ impl DataDecoder { /// `Note:` This method will pop `2` bytes from the internal vector for each byte returned. /// pub fn pop_vec(&mut self, count: usize) -> Vec { - assert!(self.bytes.len() >= count, "insufficient values available"); + debug_assert!(self.bytes.len() >= count, "insufficient values available"); let mut bytes = Vec::with_capacity(count); for _ in 0..count {