@@ -3,14 +3,15 @@ use std::{fs, path::Path, sync::mpsc, time::Instant};
33use cow_utils:: CowUtils ;
44use rayon:: prelude:: * ;
55
6- use oxc_allocator:: Allocator ;
6+ use oxc_allocator:: AllocatorPool ;
77use oxc_diagnostics:: { DiagnosticSender , DiagnosticService , OxcDiagnostic } ;
88use oxc_formatter:: { FormatOptions , Formatter , enable_jsx_source_type, get_parse_options} ;
99use oxc_parser:: Parser ;
1010
1111use crate :: { command:: OutputOptions , walk:: WalkEntry } ;
1212
1313pub struct FormatService {
14+ allocator_pool : AllocatorPool ,
1415 cwd : Box < Path > ,
1516 output_options : OutputOptions ,
1617 format_options : FormatOptions ,
@@ -19,11 +20,17 @@ pub struct FormatService {
1920}
2021
2122impl FormatService {
22- pub fn new < T > ( cwd : T , output_options : OutputOptions , format_options : FormatOptions ) -> Self
23+ pub fn new < T > (
24+ allocator_pool : AllocatorPool ,
25+ cwd : T ,
26+ output_options : OutputOptions ,
27+ format_options : FormatOptions ,
28+ ) -> Self
2329 where
2430 T : Into < Box < Path > > ,
2531 {
2632 Self {
33+ allocator_pool,
2734 cwd : cwd. into ( ) ,
2835 output_options,
2936 format_options,
@@ -69,10 +76,8 @@ impl FormatService {
6976 let path = & entry. path ;
7077 let source_type = enable_jsx_source_type ( entry. source_type ) ;
7178
72- // TODO: Use `read_to_arena_str()` like `oxlint`?
79+ let allocator = self . allocator_pool . get ( ) ;
7380 let source_text = fs:: read_to_string ( path) . expect ( "Failed to read file" ) ;
74- // TODO: Use `AllocatorPool.get()` like `oxlint`?
75- let allocator = Allocator :: new ( ) ;
7681
7782 let ret = Parser :: new ( & allocator, & source_text, source_type)
7883 . with_options ( get_parse_options ( ) )
0 commit comments