From 93d9994859f1f46a4dd75e052e72b8f7a70eac61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20=E2=80=9Cpep=E2=80=9D=20Buquet?= Date: Tue, 30 Jun 2020 18:30:15 +0200 Subject: [PATCH] pkstrings: convert HEXTOSTR to Vec MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maxime “pep” Buquet --- pkstrings/src/lib.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/pkstrings/src/lib.rs b/pkstrings/src/lib.rs index 2216e40..f1ee4e7 100644 --- a/pkstrings/src/lib.rs +++ b/pkstrings/src/lib.rs @@ -114,7 +114,8 @@ lazy_static! { } map }; - static ref HEXTOSTR: HashMap = { + + static ref HEXTOSTR: Vec> = { let tmp = [ (0x80, 'A'), (0x81, 'B'), @@ -202,11 +203,11 @@ lazy_static! { (0x50, '@'), ]; - let mut map = HashMap::new(); + let mut vec: Vec> = [None; 255].to_vec(); for (k, v) in tmp.iter() { - map.insert(*k, *v); + vec[*k] = Some(*v); } - map + vec }; } @@ -240,8 +241,9 @@ impl TryFrom<&[u8]> for PKString { let placeholder = '_'; for ord in data { - if let Some(chr) = HEXTOSTR.get(&ord) { - buf.push(*chr); + let ord = *ord as usize; + if let Some(chr) = HEXTOSTR[ord] { + buf.push(chr.clone()); } else { buf.push(placeholder); }