improved performance and benchmarking

This commit is contained in:
Simon Gardling
2022-05-04 10:06:38 -04:00
parent 452820ce26
commit d57609217a
3 changed files with 33 additions and 26 deletions

View File

@@ -129,22 +129,10 @@ fn prettyify_function_str(func: &str) -> String {
}
pub const VALID_VARIABLES: [char; 5] = ['x', 'X', 'e', 'E', 'π'];
const LETTERS: [char; 52] = [
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's',
't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L',
'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
];
const NUMBERS: [char; 10] = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'];
#[inline]
pub fn is_variable(c: &char) -> bool { VALID_VARIABLES.contains(&c) }
#[inline]
pub fn is_letter(c: &char) -> bool { LETTERS.contains(&c) }
#[inline]
pub fn is_number(c: &char) -> bool { NUMBERS.contains(&c) }
/// Adds asterisks where needed in a function
pub fn process_func_str(function_in: &str) -> String {
if function_in.is_empty() {

View File

@@ -1,4 +1,4 @@
use crate::parsing::{is_letter, is_number, is_variable};
use crate::parsing::is_variable;
pub const HINT_EMPTY: Hint = Hint::Single("x^2");
const HINT_CLOSED_PARENS: Hint = Hint::Single(")");
@@ -40,7 +40,6 @@ pub fn split_function_chars(chars: &[char]) -> Vec<String> {
// Buffer used to store data ready to be appended
let mut buffer: Vec<&char> = Vec::with_capacity(chars.len());
#[derive(Default)]
struct BoolSlice {
closing_parens: bool,
number: bool,
@@ -59,17 +58,25 @@ pub fn split_function_chars(chars: &[char]) -> Vec<String> {
fn is_number(&self) -> bool { self.number && !self.masked_num }
}
let mut prev_char: BoolSlice = BoolSlice::default();
let mut prev_char: BoolSlice = BoolSlice {
closing_parens: false,
number: false,
letter: false,
variable: false,
masked_num: false,
masked_var: false,
exists: false,
};
for c in chars {
// Set data about current character
let mut curr_c = {
let isnumber = is_number(c);
let isnumber = c.is_ascii_digit();
let isvariable = is_variable(c);
BoolSlice {
closing_parens: c == &')',
number: isnumber,
letter: is_letter(c),
letter: c.is_ascii_alphabetic(),
variable: isvariable,
masked_num: match isnumber {
true => prev_char.masked_num,