From 77a23eaf8dfd0bef75b092086c7cb9bc290982da Mon Sep 17 00:00:00 2001 From: Metaflame Date: Tue, 3 Mar 2026 11:29:25 +0100 Subject: [PATCH] Cleanup --- src/lib.rs | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index fc1f9ac..a779978 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -237,21 +237,11 @@ fn plc_ident_to_bytes(ident: &str) -> Option<[u8; 15]> { return None; } - // All bytes are already validated - fn base32_to_byte(val: u8) -> u8 { - // try to subtract 'a' - // a..=z -> 0..=25 - // 0..9 underflows, setting the carry - // if so, re-add 'a', subtract '2' instead, and offset by another 26 - // this compiles to branchless code - let (val, carry) = val.overflowing_sub(b'a'); - val.wrapping_add((carry as u8) * (b'a' - b'2' + 26)) - } - let mut out = [0u8; 15]; #[inline] fn pack_bytes(ident_bytes: &[u8]) -> u64 { + // Note: all ident_bytes must be valid base32 chars! ('a'..='z', '2'..='7') debug_assert_eq!(ident_bytes.len(), 8); let bytes = u64::from_le_bytes([ @@ -267,6 +257,7 @@ fn plc_ident_to_bytes(ident: &str) -> Option<[u8; 15]> { // Here we treat the u64 as packed u8 values // There are some add/sub ops, but none of them should overflow within their u8 + // All bytes are already validated when this function is used // For reference: // b'2' = 50 = 0x32 -- 2.51.2