mirror of
https://github.com/crate-ci/typos.git
synced 2024-11-22 09:01:04 -05:00
refactor(parser): Share a parser across calls
This commit is contained in:
parent
36fefc166e
commit
3e678cca1e
3 changed files with 18 additions and 9 deletions
|
@ -13,13 +13,14 @@ fn process_empty(b: &mut test::Bencher) {
|
||||||
sample_path.write_str(data::EMPTY).unwrap();
|
sample_path.write_str(data::EMPTY).unwrap();
|
||||||
|
|
||||||
let corrections = typos::Dictionary::new();
|
let corrections = typos::Dictionary::new();
|
||||||
|
let parser = typos::tokens::Parser::new();
|
||||||
b.iter(|| {
|
b.iter(|| {
|
||||||
typos::process_file(
|
typos::process_file(
|
||||||
sample_path.path(),
|
sample_path.path(),
|
||||||
&corrections,
|
&corrections,
|
||||||
true,
|
true,
|
||||||
true,
|
true,
|
||||||
true,
|
&parser,
|
||||||
false,
|
false,
|
||||||
typos::report::print_silent,
|
typos::report::print_silent,
|
||||||
)
|
)
|
||||||
|
@ -35,13 +36,14 @@ fn process_no_tokens(b: &mut test::Bencher) {
|
||||||
sample_path.write_str(data::NO_TOKENS).unwrap();
|
sample_path.write_str(data::NO_TOKENS).unwrap();
|
||||||
|
|
||||||
let corrections = typos::Dictionary::new();
|
let corrections = typos::Dictionary::new();
|
||||||
|
let parser = typos::tokens::Parser::new();
|
||||||
b.iter(|| {
|
b.iter(|| {
|
||||||
typos::process_file(
|
typos::process_file(
|
||||||
sample_path.path(),
|
sample_path.path(),
|
||||||
&corrections,
|
&corrections,
|
||||||
true,
|
true,
|
||||||
true,
|
true,
|
||||||
true,
|
&parser,
|
||||||
false,
|
false,
|
||||||
typos::report::print_silent,
|
typos::report::print_silent,
|
||||||
)
|
)
|
||||||
|
@ -57,13 +59,14 @@ fn process_single_token(b: &mut test::Bencher) {
|
||||||
sample_path.write_str(data::SINGLE_TOKEN).unwrap();
|
sample_path.write_str(data::SINGLE_TOKEN).unwrap();
|
||||||
|
|
||||||
let corrections = typos::Dictionary::new();
|
let corrections = typos::Dictionary::new();
|
||||||
|
let parser = typos::tokens::Parser::new();
|
||||||
b.iter(|| {
|
b.iter(|| {
|
||||||
typos::process_file(
|
typos::process_file(
|
||||||
sample_path.path(),
|
sample_path.path(),
|
||||||
&corrections,
|
&corrections,
|
||||||
true,
|
true,
|
||||||
true,
|
true,
|
||||||
true,
|
&parser,
|
||||||
false,
|
false,
|
||||||
typos::report::print_silent,
|
typos::report::print_silent,
|
||||||
)
|
)
|
||||||
|
@ -79,13 +82,14 @@ fn process_sherlock(b: &mut test::Bencher) {
|
||||||
sample_path.write_str(data::SHERLOCK).unwrap();
|
sample_path.write_str(data::SHERLOCK).unwrap();
|
||||||
|
|
||||||
let corrections = typos::Dictionary::new();
|
let corrections = typos::Dictionary::new();
|
||||||
|
let parser = typos::tokens::Parser::new();
|
||||||
b.iter(|| {
|
b.iter(|| {
|
||||||
typos::process_file(
|
typos::process_file(
|
||||||
sample_path.path(),
|
sample_path.path(),
|
||||||
&corrections,
|
&corrections,
|
||||||
true,
|
true,
|
||||||
true,
|
true,
|
||||||
true,
|
&parser,
|
||||||
false,
|
false,
|
||||||
typos::report::print_silent,
|
typos::report::print_silent,
|
||||||
)
|
)
|
||||||
|
@ -101,13 +105,14 @@ fn process_code(b: &mut test::Bencher) {
|
||||||
sample_path.write_str(data::CODE).unwrap();
|
sample_path.write_str(data::CODE).unwrap();
|
||||||
|
|
||||||
let corrections = typos::Dictionary::new();
|
let corrections = typos::Dictionary::new();
|
||||||
|
let parser = typos::tokens::Parser::new();
|
||||||
b.iter(|| {
|
b.iter(|| {
|
||||||
typos::process_file(
|
typos::process_file(
|
||||||
sample_path.path(),
|
sample_path.path(),
|
||||||
&corrections,
|
&corrections,
|
||||||
true,
|
true,
|
||||||
true,
|
true,
|
||||||
true,
|
&parser,
|
||||||
false,
|
false,
|
||||||
typos::report::print_silent,
|
typos::report::print_silent,
|
||||||
)
|
)
|
||||||
|
@ -123,13 +128,14 @@ fn process_corpus(b: &mut test::Bencher) {
|
||||||
sample_path.write_str(data::CORPUS).unwrap();
|
sample_path.write_str(data::CORPUS).unwrap();
|
||||||
|
|
||||||
let corrections = typos::Dictionary::new();
|
let corrections = typos::Dictionary::new();
|
||||||
|
let parser = typos::tokens::Parser::new();
|
||||||
b.iter(|| {
|
b.iter(|| {
|
||||||
typos::process_file(
|
typos::process_file(
|
||||||
sample_path.path(),
|
sample_path.path(),
|
||||||
&corrections,
|
&corrections,
|
||||||
true,
|
true,
|
||||||
true,
|
true,
|
||||||
true,
|
&parser,
|
||||||
false,
|
false,
|
||||||
typos::report::print_silent,
|
typos::report::print_silent,
|
||||||
)
|
)
|
||||||
|
|
|
@ -19,11 +19,10 @@ pub fn process_file(
|
||||||
dictionary: &Dictionary,
|
dictionary: &Dictionary,
|
||||||
check_filenames: bool,
|
check_filenames: bool,
|
||||||
check_files: bool,
|
check_files: bool,
|
||||||
ignore_hex: bool,
|
parser: &tokens::Parser,
|
||||||
binary: bool,
|
binary: bool,
|
||||||
report: report::Report,
|
report: report::Report,
|
||||||
) -> Result<bool, failure::Error> {
|
) -> Result<bool, failure::Error> {
|
||||||
let parser = tokens::ParserBuilder::new().ignore_hex(ignore_hex).build();
|
|
||||||
let mut typos_found = false;
|
let mut typos_found = false;
|
||||||
|
|
||||||
if check_filenames {
|
if check_filenames {
|
||||||
|
|
|
@ -261,6 +261,10 @@ fn run() -> Result<i32, failure::Error> {
|
||||||
let ignore_hex = options.ignore_hex().unwrap_or(true);
|
let ignore_hex = options.ignore_hex().unwrap_or(true);
|
||||||
let binary = options.binary().unwrap_or(false);
|
let binary = options.binary().unwrap_or(false);
|
||||||
|
|
||||||
|
let parser = typos::tokens::ParserBuilder::new()
|
||||||
|
.ignore_hex(ignore_hex)
|
||||||
|
.build();
|
||||||
|
|
||||||
let first_path = &options
|
let first_path = &options
|
||||||
.path
|
.path
|
||||||
.get(0)
|
.get(0)
|
||||||
|
@ -284,7 +288,7 @@ fn run() -> Result<i32, failure::Error> {
|
||||||
&dictionary,
|
&dictionary,
|
||||||
check_filenames,
|
check_filenames,
|
||||||
check_files,
|
check_files,
|
||||||
ignore_hex,
|
&parser,
|
||||||
binary,
|
binary,
|
||||||
options.format.report(),
|
options.format.report(),
|
||||||
)? {
|
)? {
|
||||||
|
|
Loading…
Reference in a new issue