From 0c9276482d1508480ca247183853a31b762d25cf Mon Sep 17 00:00:00 2001 From: Daniel Schadt Date: Tue, 10 Dec 2019 14:17:54 +0100 Subject: make skill lookup table static --- src/bt.rs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'src/bt.rs') diff --git a/src/bt.rs b/src/bt.rs index 293e3d4..aac8484 100644 --- a/src/bt.rs +++ b/src/bt.rs @@ -377,11 +377,17 @@ impl BuildTemplate { } } -static JSON_PALETTE: &str = include_str!("skill_palette.json"); +lazy_static! { + static ref PALETTE_MAPPING: Vec<(u32, u32)> = + serde_json::from_str(include_str!("skill_palette.json")).unwrap(); +} + +// Those functions do linear searches, but the list only has about 400 items, which should be okay. +// If performance becomes an issue, we can always create hash tables or do a binary search, +// however, since we need both directions, we would need double the memory to keep the second map. fn skill_id_to_palette_id(input: u32) -> u32 { - let lookup_table: Vec<(u32, u32)> = serde_json::from_str(JSON_PALETTE).unwrap(); - for (skill, palette) in &lookup_table { + for (skill, palette) in PALETTE_MAPPING.iter() { if *skill == input { return *palette; } @@ -390,8 +396,7 @@ fn skill_id_to_palette_id(input: u32) -> u32 { } fn palette_id_to_skill_id(input: u32) -> u32 { - let lookup_table: Vec<(u32, u32)> = serde_json::from_str(JSON_PALETTE).unwrap(); - for (skill, palette) in &lookup_table { + for (skill, palette) in PALETTE_MAPPING.iter() { if *palette == input { return *skill; } -- cgit v1.2.3