mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-03 07:04:53 +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
|
@ -40,7 +40,7 @@ impl<'a> Printer<'a> {
|
|||
Self {
|
||||
source_code,
|
||||
options,
|
||||
state: PrinterState::default(),
|
||||
state: PrinterState::with_capacity(source_code.as_str().len()),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -757,6 +757,15 @@ struct PrinterState<'a> {
|
|||
fits_queue: Vec<&'a [FormatElement]>,
|
||||
}
|
||||
|
||||
impl<'a> PrinterState<'a> {
|
||||
fn with_capacity(capacity: usize) -> Self {
|
||||
Self {
|
||||
buffer: String::with_capacity(capacity),
|
||||
..Self::default()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Tracks the mode in which groups with ids are printed. Stores the groups at `group.id()` index.
|
||||
/// This is based on the assumption that the group ids for a single document are dense.
|
||||
#[derive(Debug, Default)]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue