From 5f4ceda88c7299deb317f8d22a99ab2521c5a380 Mon Sep 17 00:00:00 2001 From: Igor Tolmachev Date: Wed, 17 Jul 2024 17:38:19 +0900 Subject: Add more `#[inline]` markers --- src/zip/cp437.rs | 2 ++ src/zip/encryption.rs | 22 +++++++++++----------- src/zip/error.rs | 2 +- src/zip/structs.rs | 2 ++ 4 files changed, 16 insertions(+), 12 deletions(-) (limited to 'src/zip') diff --git a/src/zip/cp437.rs b/src/zip/cp437.rs index 6f6731a..91a3c00 100644 --- a/src/zip/cp437.rs +++ b/src/zip/cp437.rs @@ -343,6 +343,7 @@ pub fn is_cp437(char: char) -> bool { impl FromCp437> for String { type Value = Self; + #[inline] fn from_cp437(bytes: Vec) -> Self { Self::from_cp437(bytes.as_slice()) } @@ -351,6 +352,7 @@ impl FromCp437> for String { impl FromCp437<[u8; S]> for String { type Value = Self; + #[inline] fn from_cp437(bytes: [u8; S]) -> Self { Self::from_cp437(bytes.as_slice()) } diff --git a/src/zip/encryption.rs b/src/zip/encryption.rs index 76824a1..f317245 100644 --- a/src/zip/encryption.rs +++ b/src/zip/encryption.rs @@ -7,22 +7,22 @@ const TABLE: [u32; 256] = generate_table(); const fn generate_table() -> [u32; 256] { let mut table = [0; 256]; - let mut b = 0; - while b <= 255 { - let mut crc = b as u32; + let mut i = 0; + while i <= 255 { + let mut t = i as u32; - let mut i = 0; - while i < 8 { - if (crc & 1) > 0 { - crc = (crc >> 1) ^ 0xEDB88320 + let mut j = 0; + while j < 8 { + if (t & 1) > 0 { + t = (t >> 1) ^ 0xEDB88320 } else { - crc >>= 1 + t >>= 1 } - i += 1; + j += 1; } - table[b] = crc; - b += 1 + table[i] = t; + i += 1 } table diff --git a/src/zip/error.rs b/src/zip/error.rs index 525a67b..5573cf8 100644 --- a/src/zip/error.rs +++ b/src/zip/error.rs @@ -29,7 +29,7 @@ pub enum ZipError { impl From for ArchiveError { fn from(value: ZipError) -> Self { Self::Archivator { - module: "Zip".to_string(), + module: "Zip", error: value, } } diff --git a/src/zip/structs.rs b/src/zip/structs.rs index 9fd1aeb..ebecae7 100644 --- a/src/zip/structs.rs +++ b/src/zip/structs.rs @@ -58,11 +58,13 @@ pub struct ExtraHeader { pub size: u16, } +#[inline] #[allow(dead_code)] pub fn serialize(object: &mut T) -> StructResult> { Settings::new(ByteOrder::Le, VariantIndexType::U8).serialize(object) } +#[inline] pub fn deserialize<'de, T: Deserialize<'de>>(object: &'de [u8]) -> StructResult { Settings::new(ByteOrder::Le, VariantIndexType::U8).deserialize(object) } -- cgit v1.2.3