mirror of
https://github.com/crate-ci/typos.git
synced 2026-10-17 17:45:10 +02:00
bench: Remove trie
This commit is contained in:
@@ -4,7 +4,6 @@
|
||||
mod aho_corasick_codegen;
|
||||
mod cased_map_codegen;
|
||||
mod map_codegen;
|
||||
mod trie_codegen;
|
||||
|
||||
static AHO_CORASICK: std::sync::LazyLock<aho_corasick_codegen::Word> =
|
||||
std::sync::LazyLock::new(aho_corasick_codegen::Word::new);
|
||||
@@ -33,11 +32,6 @@ mod miss {
|
||||
map_codegen::WORD.find(&word)
|
||||
}
|
||||
|
||||
#[divan::bench(args = [unicase::UniCase::new(MISS)])]
|
||||
fn trie(word: unicase::UniCase<&str>) -> Option<&'static &[&str]> {
|
||||
trie_codegen::WORD.find(&word)
|
||||
}
|
||||
|
||||
#[divan::bench(args = [unicase::UniCase::new(MISS)])]
|
||||
fn aho_corasick(word: unicase::UniCase<&str>) -> Option<&'static &[&str]> {
|
||||
AHO_CORASICK.find(&word)
|
||||
@@ -59,11 +53,6 @@ mod hit {
|
||||
map_codegen::WORD.find(&word)
|
||||
}
|
||||
|
||||
#[divan::bench(args = [unicase::UniCase::new(HIT)])]
|
||||
fn trie(word: unicase::UniCase<&str>) -> Option<&'static &[&str]> {
|
||||
trie_codegen::WORD.find(&word)
|
||||
}
|
||||
|
||||
#[divan::bench(args = [unicase::UniCase::new(HIT)])]
|
||||
fn aho_corasick(word: unicase::UniCase<&str>) -> Option<&'static &[&str]> {
|
||||
AHO_CORASICK.find(&word)
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -2,15 +2,6 @@
|
||||
fn codegen() {
|
||||
const DICT: &[u8] = include_bytes!("../assets/words.csv");
|
||||
|
||||
let mut trie_content = vec![];
|
||||
generate_trie(&mut trie_content, "WORD", DICT);
|
||||
let trie_content = String::from_utf8(trie_content).unwrap();
|
||||
let trie_content = codegenrs::rustfmt(&trie_content, None).unwrap();
|
||||
snapbox::assert_data_eq!(
|
||||
&trie_content,
|
||||
snapbox::file!["../benches/benches/trie_codegen.rs"].raw()
|
||||
);
|
||||
|
||||
let mut map_content = vec![];
|
||||
generate_map(&mut map_content, "WORD", DICT);
|
||||
let map_content = String::from_utf8(map_content).unwrap();
|
||||
@@ -41,43 +32,6 @@ fn codegen() {
|
||||
snapbox::assert_data_eq!(&map_content, snapbox::file!["../src/word_codegen.rs"].raw());
|
||||
}
|
||||
|
||||
fn generate_trie<W: std::io::Write>(file: &mut W, name: &str, dict: &[u8]) {
|
||||
writeln!(
|
||||
file,
|
||||
"// This file is @generated by {}",
|
||||
file!().replace('\\', "/")
|
||||
)
|
||||
.unwrap();
|
||||
writeln!(file, "#![allow(clippy::unreadable_literal)]",).unwrap();
|
||||
writeln!(file, "#![allow(unreachable_pub)]",).unwrap();
|
||||
writeln!(file).unwrap();
|
||||
|
||||
let records: Vec<_> = csv::ReaderBuilder::new()
|
||||
.has_headers(false)
|
||||
.flexible(true)
|
||||
.from_reader(dict)
|
||||
.records()
|
||||
.map(|r| r.unwrap())
|
||||
.collect();
|
||||
dictgen::DictGen::new()
|
||||
.name(name)
|
||||
.value_type("&[&str]")
|
||||
.trie()
|
||||
.write(
|
||||
file,
|
||||
records.iter().map(|record| {
|
||||
let mut record_fields = record.iter();
|
||||
let key = record_fields.next().unwrap();
|
||||
let value = format!(
|
||||
"&[{}]",
|
||||
itertools::join(record_fields.map(|field| format!(r#""{field}""#)), ", ")
|
||||
);
|
||||
(key, value)
|
||||
}),
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
fn generate_cased_map<W: std::io::Write>(file: &mut W, name: &str, dict: &[u8]) {
|
||||
writeln!(
|
||||
file,
|
||||
|
||||
Reference in New Issue
Block a user