mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-04 02:38:25 +00:00
Estimate expected VecBuffer
size (#6612)
This commit is contained in:
parent
95f78821ad
commit
7ee2ae8395
1 changed files with 6 additions and 2 deletions
|
@ -778,9 +778,13 @@ pub fn format<Context>(
|
|||
where
|
||||
Context: FormatContext,
|
||||
{
|
||||
let source_length = context.source_code().as_str().len();
|
||||
// Use a simple heuristic to guess the number of expected format elements.
|
||||
// See [#6612](https://github.com/astral-sh/ruff/pull/6612) for more details on how the formula was determined. Changes to our formatter, or supporting
|
||||
// more languages may require fine tuning the formula.
|
||||
let estimated_buffer_size = source_length / 2;
|
||||
let mut state = FormatState::new(context);
|
||||
let mut buffer =
|
||||
VecBuffer::with_capacity(state.context().source_code().as_str().len(), &mut state);
|
||||
let mut buffer = VecBuffer::with_capacity(estimated_buffer_size, &mut state);
|
||||
|
||||
buffer.write_fmt(arguments)?;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue