mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-30 22:01:47 +00:00
Printer: Reserve buffer upfront (#6550)
This commit is contained in:
parent
9584f613b9
commit
910dbbd9b6
2 changed files with 18 additions and 9 deletions
|
@ -319,20 +319,20 @@ where
|
|||
Context: FormatContext,
|
||||
{
|
||||
pub fn print(&self) -> PrintResult<Printed> {
|
||||
let source_code = self.context.source_code();
|
||||
let print_options = self.context.options().as_print_options();
|
||||
let printed = Printer::new(source_code, print_options).print(&self.document)?;
|
||||
|
||||
Ok(printed)
|
||||
let printer = self.create_printer();
|
||||
printer.print(&self.document)
|
||||
}
|
||||
|
||||
pub fn print_with_indent(&self, indent: u16) -> PrintResult<Printed> {
|
||||
let printer = self.create_printer();
|
||||
printer.print_with_indent(&self.document, indent)
|
||||
}
|
||||
|
||||
fn create_printer(&self) -> Printer {
|
||||
let source_code = self.context.source_code();
|
||||
let print_options = self.context.options().as_print_options();
|
||||
let printed =
|
||||
Printer::new(source_code, print_options).print_with_indent(&self.document, indent)?;
|
||||
|
||||
Ok(printed)
|
||||
Printer::new(source_code, print_options)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue