mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-18 17:40:37 +00:00
Remove string allocation in relative import formatting (#7743)
This commit is contained in:
parent
2838f7af98
commit
d8a6279fe5
1 changed files with 6 additions and 5 deletions
|
@ -20,16 +20,17 @@ impl FormatNodeRule<StmtImportFrom> for FormatStmtImportFrom {
|
|||
range: _,
|
||||
} = item;
|
||||
|
||||
let level_str = level
|
||||
.map(|level| ".".repeat(level as usize))
|
||||
.unwrap_or(String::default());
|
||||
|
||||
write!(
|
||||
f,
|
||||
[
|
||||
token("from"),
|
||||
space(),
|
||||
text(&level_str, None),
|
||||
format_with(|f| {
|
||||
for _ in 0..level.unwrap_or(0) {
|
||||
token(".").fmt(f)?;
|
||||
}
|
||||
Ok(())
|
||||
}),
|
||||
module.as_ref().map(AsFormat::format),
|
||||
space(),
|
||||
token("import"),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue