Skip to content

Commit

Permalink
Improve lint method performance.
Browse files Browse the repository at this point in the history
  • Loading branch information
huacnlee committed Dec 5, 2023
1 parent fdb50e1 commit 0f8a5c6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -424,13 +424,13 @@ spellcheck_50 time: [1.6012 µs 1.6122 µs 1.6306 µs]
spellcheck_100 time: [3.0968 µs 3.1696 µs 3.2653 µs]
spellcheck_400 time: [10.136 µs 10.478 µs 10.898 µs]
lint_markdown time: [1.1195 ms 1.1205 ms 1.1215 ms]
lint_json time: [67.764 µs 68.341 µs 69.137 µs]
lint_html time: [280.87 µs 281.44 µs 282.20 µs]
lint_javascript time: [123.99 µs 125.50 µs 128.38 µs]
lint_yaml time: [433.41 µs 441.09 µs 452.74 µs]
lint_to_json time: [1.8391 ms 1.8428 ms 1.8476 ms]
lint_to_diff time: [1.8632 ms 1.8801 ms 1.9030 ms]
lint_markdown time: [937.57 µs 942.59 µs 949.15 µs]
lint_json time: [59.174 µs 60.302 µs 61.763 µs]
lint_html time: [238.03 µs 241.38 µs 245.77 µs]
lint_javascript time: [111.64 µs 113.05 µs 114.82 µs]
lint_yaml time: [348.56 µs 350.11 µs 352.80 µs]
lint_to_json time: [941.25 µs 948.95 µs 958.26 µs]
lint_to_diff time: [1.0573 ms 1.0823 ms 1.1134 ms]
```

### Real world benchmark
Expand Down
8 changes: 4 additions & 4 deletions autocorrect/src/rule/rule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,23 +38,23 @@ impl Rule {
if result.out.ne(&new) {
result.severity = Severity::Error;
}

result.out = new;
}

pub fn lint(&self, result: &mut RuleResult) {
if self.severity() == SeverityMode::Off {
return;
}
let input = result.out.clone();
result.out = (self.format_fn)(&input);
if result.out.ne(&input) && result.severity == Severity::Pass {

let new = (self.format_fn)(&result.out);
if result.out.ne(&new) && result.severity == Severity::Pass {
if self.severity() == SeverityMode::Warning {
result.severity = Severity::Warning;
} else {
result.severity = Severity::Error;
}
}
result.out = new;
}

fn severity(&self) -> SeverityMode {
Expand Down

0 comments on commit 0f8a5c6

Please sign in to comment.