aboutsummaryrefslogtreecommitdiff
path: root/src/bt.rs
diff options
context:
space:
mode:
authorDaniel Schadt <kingdread@gmx.de>2019-12-10 14:17:54 +0100
committerDaniel Schadt <kingdread@gmx.de>2019-12-10 14:17:54 +0100
commit0c9276482d1508480ca247183853a31b762d25cf (patch)
tree49248d34082ed6b3db0bab21a20cc48f5803898a /src/bt.rs
parent8212e56fd470985bcb5dca94defc40854fb95894 (diff)
downloadkondou-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.rs15
1 files changed, 10 insertions, 5 deletions
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;
}