diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index dbabf12..a43d416 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -43,7 +43,8 @@ jobs: version: latest - run: cargo test-all-features - # - name: Test Parsing - # uses: actions-rs/cargo@v1 - # with: - # command: test --package parsing + - name: Test Parsing + uses: actions-rs/cargo@v1 + with: + command: test + args: --package parsing diff --git a/Cargo.lock b/Cargo.lock index 57c19d4..9c531ab 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -663,7 +663,7 @@ checksum = "9ea835d29036a4087793836fa931b08837ad5e957da9e23886b29586fb9b6650" [[package]] name = "eframe" version = "0.18.0" -source = "git+https://github.com/Titaniumtown/egui.git#f77c972b1405666b9f0250c44d7b488ac40e1f04" +source = "git+https://github.com/Titaniumtown/egui.git#ffef46110abfe2d0c9891d3e457eccb1b8a75842" dependencies = [ "bytemuck", "egui", @@ -683,7 +683,7 @@ dependencies = [ [[package]] name = "egui" version = "0.18.1" -source = "git+https://github.com/Titaniumtown/egui.git#f77c972b1405666b9f0250c44d7b488ac40e1f04" +source = "git+https://github.com/Titaniumtown/egui.git#ffef46110abfe2d0c9891d3e457eccb1b8a75842" dependencies = [ "ahash", "epaint", @@ -694,7 +694,7 @@ dependencies = [ [[package]] name = "egui-winit" version = "0.18.0" -source = "git+https://github.com/Titaniumtown/egui.git#f77c972b1405666b9f0250c44d7b488ac40e1f04" +source = "git+https://github.com/Titaniumtown/egui.git#ffef46110abfe2d0c9891d3e457eccb1b8a75842" dependencies = [ "arboard", "egui", @@ -707,7 +707,7 @@ dependencies = [ [[package]] name = "egui_glow" version = "0.18.0" -source = "git+https://github.com/Titaniumtown/egui.git#f77c972b1405666b9f0250c44d7b488ac40e1f04" +source = "git+https://github.com/Titaniumtown/egui.git#ffef46110abfe2d0c9891d3e457eccb1b8a75842" dependencies = [ "bytemuck", "egui", @@ -727,7 +727,7 @@ checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457" [[package]] name = "emath" version = "0.18.0" -source = "git+https://github.com/Titaniumtown/egui.git#f77c972b1405666b9f0250c44d7b488ac40e1f04" +source = "git+https://github.com/Titaniumtown/egui.git#ffef46110abfe2d0c9891d3e457eccb1b8a75842" dependencies = [ "bytemuck", ] @@ -735,7 +735,7 @@ dependencies = [ [[package]] name = "epaint" version = "0.18.1" -source = "git+https://github.com/Titaniumtown/egui.git#f77c972b1405666b9f0250c44d7b488ac40e1f04" +source = "git+https://github.com/Titaniumtown/egui.git#ffef46110abfe2d0c9891d3e457eccb1b8a75842" dependencies = [ "ab_glyph", "ahash", @@ -2832,8 +2832,6 @@ dependencies = [ "itertools", "lazy_static", "parsing", - "phf", - "phf_codegen", "rayon", "ruzstd", "serde_json", diff --git a/Cargo.toml b/Cargo.toml index ed58b43..90c8adb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -51,7 +51,6 @@ serde_json = "1.0" tracing = "0.1" itertools = "0.10" static_assertions = "1.1" -phf = "0.10" uuid = { version = "1", features = ["v4", "fast-rng", "js"] } [dev-dependencies] @@ -60,8 +59,6 @@ benchmarks = { path = "./benchmarks" } [build-dependencies] shadow-rs = "0.11" command-run = "1.1" -phf_codegen = "0.10" -itertools = "0.10" [target.'cfg(not(target_arch = "wasm32"))'.dependencies] instant = "0.1" diff --git a/parsing/src/autocomplete_helper.rs b/parsing/src/autocomplete_helper.rs index 2a8a2ae..10e861d 100644 --- a/parsing/src/autocomplete_helper.rs +++ b/parsing/src/autocomplete_helper.rs @@ -30,9 +30,12 @@ pub fn compile_hashmap(data: Vec) -> Vec<(String, String)> { } seen_3.insert(key.clone()); - if keys.iter().filter(|a| a == &&key).count() == 1 { + + let count_keys = keys.iter().filter(|a| a == &&key).count(); + + if count_keys == 1 { output.push((key.clone(), format!(r#"Hint::Single("{}")"#, value))); - } else { + } else if count_keys > 1 { let mut multi_data = tuple_list_1 .iter() .filter(|(a, _)| a == key) @@ -40,6 +43,8 @@ pub fn compile_hashmap(data: Vec) -> Vec<(String, String)> { .collect::>(); multi_data.sort_unstable_by(|a, b| compare_len_reverse_alpha(a, b)); output.push((key.clone(), format!("Hint::Many(&{:?})", multi_data))); + } else { + panic!("Number of values for {key} is 0!"); } } output diff --git a/parsing/src/parsing.rs b/parsing/src/parsing.rs index 51354f4..4bf17b9 100644 --- a/parsing/src/parsing.rs +++ b/parsing/src/parsing.rs @@ -31,7 +31,9 @@ impl BackingFunction { match &parse_result { Err(e) => return Err(e.to_string()), Ok(_) => { - let var_names = parse_result.as_ref().unwrap().var_names().to_vec(); + let var_names = unsafe { parse_result.as_ref().unwrap_unchecked() } + .var_names() + .to_vec(); if var_names != ["x"] { let var_names_not_x: Vec<&String> = var_names @@ -50,7 +52,7 @@ impl BackingFunction { } } } - parse_result.unwrap() + unsafe { parse_result.unwrap_unchecked() } } }; diff --git a/parsing/src/suggestions.rs b/parsing/src/suggestions.rs index 69570a0..103aa1b 100644 --- a/parsing/src/suggestions.rs +++ b/parsing/src/suggestions.rs @@ -78,9 +78,9 @@ pub fn split_function_chars(chars: &[char]) -> Vec { }, } } - fn is_variable(&self) -> bool { self.variable && !self.masked_var } + const fn is_variable(&self) -> bool { self.variable && !self.masked_var } - fn is_number(&self) -> bool { self.number && !self.masked_num } + const fn is_number(&self) -> bool { self.number && !self.masked_num } } // Setup first char here @@ -178,6 +178,10 @@ pub fn generate_hint<'a>(input: &str) -> &'a Hint<'a> { let chars: Vec = input.chars().collect::>(); + unsafe { + assume(!chars.is_empty()); + } + let mut open_parens: usize = 0; let mut closed_parens: usize = 0; chars.iter().for_each(|chr| match *chr { @@ -225,13 +229,13 @@ impl<'a> std::fmt::Debug for Hint<'a> { } impl<'a> Hint<'a> { - pub fn is_none(&self) -> bool { matches!(&self, &Hint::None) } + pub const fn is_none(&self) -> bool { matches!(&self, &Hint::None) } #[allow(dead_code)] - pub fn is_some(&self) -> bool { !self.is_none() } + pub const fn is_some(&self) -> bool { !self.is_none() } #[allow(dead_code)] - pub fn is_single(&self) -> bool { matches!(&self, &Hint::Single(_)) } + pub const fn is_single(&self) -> bool { matches!(&self, &Hint::Single(_)) } } include!(concat!(env!("OUT_DIR"), "/codegen.rs")); diff --git a/src/misc.rs b/src/misc.rs index f81cd1e..ccbab6b 100644 --- a/src/misc.rs +++ b/src/misc.rs @@ -6,6 +6,7 @@ use serde_json::Value as JsonValue; use rayon::prelude::*; #[cfg(not(threading))] +#[inline] pub fn dyn_iter<'a, T>(input: &'a [T]) -> impl Iterator where &'a [T]: IntoIterator, @@ -14,6 +15,7 @@ where } #[cfg(threading)] +#[inline] pub fn dyn_iter<'a, I>(input: &'a I) -> <&'a I as IntoParallelIterator>::Iter where &'a I: IntoParallelIterator, @@ -22,6 +24,7 @@ where } #[cfg(not(threading))] +#[inline] pub fn dyn_mut_iter<'a, T>(input: &'a mut [T]) -> impl Iterator where &'a mut [T]: IntoIterator, @@ -30,6 +33,7 @@ where } #[cfg(threading)] +#[inline] pub fn dyn_mut_iter<'a, I>(input: &'a mut I) -> <&'a mut I as IntoParallelIterator>::Iter where &'a mut I: IntoParallelIterator, @@ -114,10 +118,10 @@ impl SteppedVector { } #[allow(dead_code)] - pub fn get_min(&self) -> f64 { self.min } + pub const fn get_min(&self) -> f64 { self.min } #[allow(dead_code)] - pub fn get_max(&self) -> f64 { self.max } + pub const fn get_max(&self) -> f64 { self.max } #[allow(dead_code)] pub fn get_data(&self) -> Vec { self.data.clone() } diff --git a/src/widgets.rs b/src/widgets.rs index 013fbe2..abb5b6d 100644 --- a/src/widgets.rs +++ b/src/widgets.rs @@ -34,19 +34,25 @@ impl<'a> const Default for AutoComplete<'a> { } impl<'a> AutoComplete<'a> { + #[allow(dead_code)] pub fn update_string(&mut self, string: &str) { if self.string != string { // catch empty strings here to avoid call to `generate_hint` and unnecessary logic if string.is_empty() { *self = Self::default(); } else { - self.i = 0; self.string = string.to_string(); - self.hint = generate_hint(string); + self.do_update_logic(); } } } + /// Runs update logic assuming that a change to `self.string` has been made + fn do_update_logic(&mut self) { + self.i = 0; + self.hint = generate_hint(&self.string); + } + pub fn register_movement(&mut self, movement: &Movement) { if movement == &Movement::None { return; @@ -90,8 +96,8 @@ impl<'a> AutoComplete<'a> { } pub fn apply_hint(&mut self, hint: &str) { - let new_string = self.string.clone() + hint; - self.update_string(&new_string); + self.string.push_str(hint); + self.do_update_logic(); } }