Skip to content

Commit

Permalink
perf(linter): use CompactStr in no-large-snapshots (#6402)
Browse files Browse the repository at this point in the history
  • Loading branch information
camchenry committed Oct 10, 2024
1 parent c382ec4 commit 9906849
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions crates/oxc_linter/src/rules/jest/no_large_snapshots.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use oxc_ast::{
};
use oxc_diagnostics::OxcDiagnostic;
use oxc_macros::declare_oxc_lint;
use oxc_span::{GetSpan, Span};
use oxc_span::{CompactStr, GetSpan, Span};
use regex::Regex;
use rustc_hash::FxHashMap;

Expand Down Expand Up @@ -38,7 +38,7 @@ pub struct NoLargeSnapshots(Box<NoLargeSnapshotsConfig>);
pub struct NoLargeSnapshotsConfig {
pub max_size: usize,
pub inline_max_size: usize,
pub allowed_snapshots: FxHashMap<String, Vec<String>>,
pub allowed_snapshots: FxHashMap<CompactStr, Vec<CompactStr>>,
}

impl Deref for NoLargeSnapshots {
Expand Down Expand Up @@ -281,21 +281,19 @@ impl NoLargeSnapshots {
#[allow(clippy::unnecessary_wraps)]
pub fn compile_allowed_snapshots(
matchers: &serde_json::Map<String, serde_json::Value>,
) -> Option<FxHashMap<String, Vec<String>>> {
) -> Option<FxHashMap<CompactStr, Vec<CompactStr>>> {
Some(
matchers
.iter()
.map(|(key, value)| {
let serde_json::Value::Array(configs) = value else {
return (String::from(key), vec![]);
return (CompactStr::from(key.as_str()), vec![]);
};

let configs = configs
.iter()
.filter_map(|c| c.as_str().map(std::string::ToString::to_string))
.collect();
let configs =
configs.iter().filter_map(|c| c.as_str().map(CompactStr::from)).collect();

(String::from(key), configs)
(CompactStr::from(key.as_str()), configs)
})
.collect(),
)
Expand Down

0 comments on commit 9906849

Please sign in to comment.