Skip to content

Commit eaa605e

Browse files
committed
refactor(linter): avoid some Arc::clone in linter runtime (#11388)
1 parent 1cd8b9c commit eaa605e

File tree

1 file changed

+23
-15
lines changed

1 file changed

+23
-15
lines changed

crates/oxc_linter/src/service/runtime.rs

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ impl<'l> Runtime<'l> {
249249
) {
250250
if self.resolver.is_none() {
251251
self.paths.par_iter().for_each(|path| {
252-
let output = self.process_path(Arc::clone(path), check_syntax_errors, tx_error);
252+
let output = self.process_path(path, check_syntax_errors, tx_error);
253253
let Some(entry) =
254254
ModuleToLint::from_processed_module(output.path, output.processed_module)
255255
else {
@@ -348,7 +348,7 @@ impl<'l> Runtime<'l> {
348348
let tx_process_output = tx_process_output.clone();
349349
scope.spawn(move |_| {
350350
tx_process_output
351-
.send(me.process_path(path, check_syntax_errors, tx_error))
351+
.send(me.process_path(&path, check_syntax_errors, tx_error))
352352
.unwrap();
353353
});
354354
}
@@ -383,7 +383,7 @@ impl<'l> Runtime<'l> {
383383
move |_| {
384384
tx_resolve_output
385385
.send(me.process_path(
386-
dep_path,
386+
&dep_path,
387387
check_syntax_errors,
388388
tx_error,
389389
))
@@ -734,34 +734,42 @@ impl<'l> Runtime<'l> {
734734

735735
fn process_path(
736736
&self,
737-
path: Arc<OsStr>,
737+
path: &Arc<OsStr>,
738738
check_syntax_errors: bool,
739739
tx_error: &DiagnosticSender,
740740
) -> ModuleProcessOutput {
741-
let Some(ext) = Path::new(&path).extension().and_then(OsStr::to_str) else {
742-
return ModuleProcessOutput { path, processed_module: ProcessedModule::default() };
741+
let Some(ext) = Path::new(path).extension().and_then(OsStr::to_str) else {
742+
return ModuleProcessOutput {
743+
path: Arc::clone(path),
744+
processed_module: ProcessedModule::default(),
745+
};
743746
};
744-
let Some(source_type_and_text) = self.get_source_type_and_text(Path::new(&path), ext)
745-
else {
746-
return ModuleProcessOutput { path, processed_module: ProcessedModule::default() };
747+
let Some(source_type_and_text) = self.get_source_type_and_text(Path::new(path), ext) else {
748+
return ModuleProcessOutput {
749+
path: Arc::clone(path),
750+
processed_module: ProcessedModule::default(),
751+
};
747752
};
748753

749754
let (source_type, source_text) = match source_type_and_text {
750755
Ok(source_text) => source_text,
751756
Err(e) => {
752-
tx_error.send(Some((Path::new(&path).to_path_buf(), vec![e]))).unwrap();
753-
return ModuleProcessOutput { path, processed_module: ProcessedModule::default() };
757+
tx_error.send(Some((Path::new(path).to_path_buf(), vec![e]))).unwrap();
758+
return ModuleProcessOutput {
759+
path: Arc::clone(path),
760+
processed_module: ProcessedModule::default(),
761+
};
754762
}
755763
};
756764
let mut records = SmallVec::<[Result<ResolvedModuleRecord, Vec<OxcDiagnostic>>; 1]>::new();
757765
let mut module_content: Option<ModuleContent> = None;
758766
let allocator = Allocator::default();
759-
if self.paths.contains(&path) {
767+
if self.paths.contains(path) {
760768
module_content =
761769
Some(ModuleContent::new(ModuleContentOwner { source_text, allocator }, |owner| {
762770
let mut section_contents = SmallVec::new();
763771
records = self.process_source(
764-
Path::new(&path),
772+
Path::new(path),
765773
ext,
766774
check_syntax_errors,
767775
source_type,
@@ -773,7 +781,7 @@ impl<'l> Runtime<'l> {
773781
}));
774782
} else {
775783
records = self.process_source(
776-
Path::new(&path),
784+
Path::new(path),
777785
ext,
778786
check_syntax_errors,
779787
source_type,
@@ -784,7 +792,7 @@ impl<'l> Runtime<'l> {
784792
}
785793

786794
ModuleProcessOutput {
787-
path,
795+
path: Arc::clone(path),
788796
processed_module: ProcessedModule {
789797
section_module_records: records,
790798
content: module_content,

0 commit comments

Comments
 (0)