refactor(varcon): Remove reliance on const-fn

This dropped RSS (memory usage) from 4GB to 1.5GB when compiling.

The extra `match` could impact performance but not too concerned since
the default is to not look within vars.
This commit is contained in:
Ed Page 2021-05-31 21:29:39 -05:00
parent b1cf03c7eb
commit 2b1f565eaa
3 changed files with 26899 additions and 26887 deletions

View file

@ -79,7 +79,7 @@ fn generate_variations<W: std::io::Write>(file: &mut W) {
writeln!( writeln!(
file, file,
"pub(crate) static VARS_DICTIONARY: &[(unicase::UniCase<&'static str>, &'static [(u8, &VariantsMap)])] = &[" "pub(crate) static VARS_DICTIONARY: &[(crate::EncodedStr, &[(u8, &VariantsMap)])] = &["
) )
.unwrap(); .unwrap();
let entry_sets = entry_sets(entries.iter()); let entry_sets = entry_sets(entries.iter());
@ -93,9 +93,9 @@ fn generate_variations<W: std::io::Write>(file: &mut W) {
let value = generate_link(&data); let value = generate_link(&data);
let word = unicase::UniCase::new(word); let word = unicase::UniCase::new(word);
let key = if word.is_ascii() { let key = if word.is_ascii() {
format!("unicase::UniCase::ascii({:?})", word) format!("crate::EncodedStr::Ascii({:?})", word)
} else { } else {
format!("unicase::UniCase::unicode({:?})", word) format!("crate::EncodedStr::Unicode({:?})", word)
}; };
writeln!(file, " ({}, {}),", key, &value).unwrap(); writeln!(file, " ({}, {}),", key, &value).unwrap();
smallest = std::cmp::min(smallest, word.len()); smallest = std::cmp::min(smallest, word.len());

View file

@ -7,7 +7,22 @@ pub use varcon_core::CategorySet;
pub fn find(word: &'_ unicase::UniCase<&str>) -> Option<&'static [(u8, &'static VariantsMap)]> { pub fn find(word: &'_ unicase::UniCase<&str>) -> Option<&'static [(u8, &'static VariantsMap)]> {
VARS_DICTIONARY VARS_DICTIONARY
.binary_search_by_key(word, |(key, _)| *key) .binary_search_by_key(word, |(key, _)| key.convert())
.map(|i| VARS_DICTIONARY[i].1) .map(|i| VARS_DICTIONARY[i].1)
.ok() .ok()
} }
#[derive(Copy, Clone, Debug)]
pub(crate) enum EncodedStr {
//Unicode(&'static str),
Ascii(&'static str),
}
impl EncodedStr {
fn convert(self) -> unicase::UniCase<&'static str> {
match self {
//EncodedStr::Unicode(s) => unicase::UniCase::unicode(s),
EncodedStr::Ascii(s) => unicase::UniCase::ascii(s),
}
}
}

File diff suppressed because it is too large Load diff