Skip to content

Commit 50b1786

Browse files
committed
refactor(linter): clarify usage of Allocator and AllocatorGuard (#12332)
Pure refactor. Rename vars and deref `AllocatorGuard` to `&Allocator` to make it clearer what's what. I was getting very confused when trying to understand this code!
1 parent 26d3a39 commit 50b1786

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

crates/oxc_linter/src/service/runtime.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,7 @@ impl Runtime {
498498
pub(super) fn run(&mut self, tx_error: &DiagnosticSender) {
499499
rayon::scope(|scope| {
500500
self.resolve_modules(scope, true, tx_error, |me, mut module_to_lint| {
501-
module_to_lint.content.with_dependent_mut(|_owner, dep| {
501+
module_to_lint.content.with_dependent_mut(|_allocator_guard, dep| {
502502
// If there are fixes, we will accumulate all of them and write to the file at the end.
503503
// This means we do not write multiple times to the same file if there are multiple sources
504504
// in the same file (for example, multiple scripts in an `.astro` file).
@@ -613,7 +613,7 @@ impl Runtime {
613613
rayon::scope(|scope| {
614614
self.resolve_modules(scope, true, &sender, |me, mut module| {
615615
module.content.with_dependent_mut(
616-
|_owner, ModuleContentDependent { source_text, section_contents }| {
616+
|_allocator_guard, ModuleContentDependent { source_text, section_contents }| {
617617
assert_eq!(module.section_module_records.len(), section_contents.len());
618618

619619
let rope = &Rope::from_str(source_text);
@@ -750,7 +750,7 @@ impl Runtime {
750750
rayon::scope(|scope| {
751751
self.resolve_modules(scope, check_syntax_errors, tx_error, |me, mut module| {
752752
module.content.with_dependent_mut(
753-
|_owner, ModuleContentDependent { source_text: _, section_contents }| {
753+
|_allocator_guard, ModuleContentDependent { source_text: _, section_contents }| {
754754
assert_eq!(module.section_module_records.len(), section_contents.len());
755755
for (record_result, section) in module
756756
.section_module_records
@@ -806,9 +806,9 @@ impl Runtime {
806806
let mut module_content: Option<ModuleContent> = None;
807807

808808
if self.paths.contains(path) {
809-
let allocator = self.allocator_pool.get();
809+
let allocator_guard = self.allocator_pool.get();
810810

811-
let build = ModuleContent::try_new(allocator, |allocator| {
811+
let build = ModuleContent::try_new(allocator_guard, |allocator| {
812812
let Some(stt) = self.get_source_type_and_text(Path::new(path), ext, allocator)
813813
else {
814814
return Err(());
@@ -841,9 +841,10 @@ impl Runtime {
841841
Err(()) => return default_output(),
842842
};
843843
} else {
844-
let allocator = self.allocator_pool.get();
844+
let allocator_guard = self.allocator_pool.get();
845+
let allocator = &*allocator_guard;
845846

846-
let Some(stt) = self.get_source_type_and_text(Path::new(path), ext, &allocator) else {
847+
let Some(stt) = self.get_source_type_and_text(Path::new(path), ext, allocator) else {
847848
return default_output();
848849
};
849850

@@ -861,7 +862,7 @@ impl Runtime {
861862
check_syntax_errors,
862863
source_type,
863864
source_text,
864-
&allocator,
865+
allocator,
865866
None,
866867
);
867868
}

0 commit comments

Comments
 (0)