Perf: Skip string normalization when possible (#10116)

This commit is contained in:
Micha Reiser
2024-02-26 18:35:29 +01:00
committed by GitHub
parent 15b87ea8be
commit 8dc22d5793
3 changed files with 170 additions and 88 deletions

View File

@@ -59,16 +59,16 @@ impl Format<PyFormatContext<'_>> for FormatFString<'_> {
return result;
}
let quotes = normalizer.choose_quotes(&string, &locator);
let quote_selection = normalizer.choose_quotes(&string, &locator);
let context = FStringContext::new(
string.prefix(),
quotes,
quote_selection.quotes(),
FStringLayout::from_f_string(self.value, &locator),
);
// Starting prefix and quote
write!(f, [string.prefix(), quotes])?;
write!(f, [string.prefix(), quote_selection.quotes()])?;
f.join()
.entries(
@@ -80,7 +80,7 @@ impl Format<PyFormatContext<'_>> for FormatFString<'_> {
.finish()?;
// Ending quote
quotes.fmt(f)
quote_selection.quotes().fmt(f)
}
}