diff options
author | Daniel Schadt <kingdread@gmx.de> | 2019-12-10 14:17:54 +0100 |
---|---|---|
committer | Daniel Schadt <kingdread@gmx.de> | 2019-12-10 14:17:54 +0100 |
commit | 0c9276482d1508480ca247183853a31b762d25cf (patch) | |
tree | 49248d34082ed6b3db0bab21a20cc48f5803898a /src/bt.rs | |
parent | 8212e56fd470985bcb5dca94defc40854fb95894 (diff) | |
download | kondou-0c9276482d1508480ca247183853a31b762d25cf.tar.gz kondou-0c9276482d1508480ca247183853a31b762d25cf.tar.bz2 kondou-0c9276482d1508480ca247183853a31b762d25cf.zip |
make skill lookup table static
Diffstat (limited to 'src/bt.rs')
-rw-r--r-- | src/bt.rs | 15 |
1 files changed, 10 insertions, 5 deletions
@@ -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; } |