Skip to content

Commit

Permalink
refactor(cli): Break out config->policy
Browse files Browse the repository at this point in the history
This is prep for having many policies floating around
  • Loading branch information
Ed Page committed Mar 30, 2021
1 parent b17f9c3 commit 8bcacf3
Show file tree
Hide file tree
Showing 7 changed files with 187 additions and 160 deletions.
8 changes: 8 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ toml = "0.5"
log = "0.4"
env_logger = "0.8"
bstr = "0.2"
once_cell = "1.2.0"
ahash = "0.7"
difflib = "0.4"
proc-exit = "1.0"
Expand All @@ -58,6 +59,7 @@ itertools = "0.10"
serde_json = "1.0"
encoding = "0.2"
kstring = "1.0"
typed-arena = "2.0.1"

[dev-dependencies]
assert_fs = "1.0"
Expand Down
34 changes: 10 additions & 24 deletions benches/checks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion};
use typos_cli::file::FileChecker;

fn bench_checks(c: &mut Criterion) {
let dictionary = typos_cli::dict::BuiltIn::new(Default::default());
let tokenizer = typos::tokens::Tokenizer::new();
let policy = typos_cli::policy::Policy::new()
.dictionary(&dictionary)
.tokenizer(&tokenizer);

let mut group = c.benchmark_group("checks");
for (name, sample) in data::DATA {
let len = sample.len();
Expand All @@ -13,16 +19,11 @@ fn bench_checks(c: &mut Criterion) {
let sample_path = temp.child("sample");
sample_path.write_str(sample).unwrap();

let corrections = typos_cli::dict::BuiltIn::new(Default::default());
let parser = typos::tokens::Tokenizer::new();
let settings = typos_cli::file::CheckSettings::new();
b.iter(|| {
typos_cli::file::FoundFiles.check_file(
sample_path.path(),
true,
&settings,
&parser,
&corrections,
&policy,
&typos_cli::report::PrintSilent,
)
});
Expand All @@ -34,16 +35,11 @@ fn bench_checks(c: &mut Criterion) {
let sample_path = temp.child("sample");
sample_path.write_str(sample).unwrap();

let corrections = typos_cli::dict::BuiltIn::new(Default::default());
let parser = typos::tokens::Tokenizer::new();
let settings = typos_cli::file::CheckSettings::new();
b.iter(|| {
typos_cli::file::Identifiers.check_file(
sample_path.path(),
true,
&settings,
&parser,
&corrections,
&policy,
&typos_cli::report::PrintSilent,
)
});
Expand All @@ -55,16 +51,11 @@ fn bench_checks(c: &mut Criterion) {
let sample_path = temp.child("sample");
sample_path.write_str(sample).unwrap();

let corrections = typos_cli::dict::BuiltIn::new(Default::default());
let parser = typos::tokens::Tokenizer::new();
let settings = typos_cli::file::CheckSettings::new();
b.iter(|| {
typos_cli::file::Words.check_file(
sample_path.path(),
true,
&settings,
&parser,
&corrections,
&policy,
&typos_cli::report::PrintSilent,
)
});
Expand All @@ -76,16 +67,11 @@ fn bench_checks(c: &mut Criterion) {
let sample_path = temp.child("sample");
sample_path.write_str(sample).unwrap();

let corrections = typos_cli::dict::BuiltIn::new(Default::default());
let parser = typos::tokens::Tokenizer::new();
let settings = typos_cli::file::CheckSettings::new();
b.iter(|| {
typos_cli::file::Typos.check_file(
sample_path.path(),
true,
&settings,
&parser,
&corrections,
&policy,
&typos_cli::report::PrintSilent,
)
});
Expand Down
Loading

0 comments on commit 8bcacf3

Please sign in to comment.