Skip to content

Commit

Permalink
Don't use Cell after all, since it's more mental overhead than it's…
Browse files Browse the repository at this point in the history
… worth
  • Loading branch information
DavisVaughan committed Jan 7, 2025
1 parent f43b7ab commit 985bf67
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions crates/air_r_formatter/src/string_literal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use biome_formatter::trivia::format_replaced;
use biome_formatter::Format;
use biome_formatter::FormatResult;
use std::borrow::Cow;
use std::cell::Cell;

use crate::context::RFormatContext;
use crate::RFormatter;
Expand Down Expand Up @@ -36,7 +35,6 @@ impl<'token> FormatStringLiteralToken<'token> {

let text = token.text_trimmed();
let text = normalize_string(text);
let text = Cell::new(text);

FormatNormalizedStringLiteralToken { token, text }
}
Expand All @@ -53,16 +51,18 @@ struct FormatNormalizedStringLiteralToken<'token> {
token: &'token RSyntaxToken,

/// The normalized text
/// Wrapped in a [`Cell`] to avoid having to clone when passing to [`syntax_token_cow_slice`]
text: Cell<Cow<'token, str>>,
text: Cow<'token, str>,
}

impl Format<RFormatContext> for FormatNormalizedStringLiteralToken<'_> {
fn fmt(&self, f: &mut Formatter<RFormatContext>) -> FormatResult<()> {
format_replaced(
self.token,
&syntax_token_cow_slice(
self.text.take(),
// Cloning the `Cow<str>` is cheap since 99% of the time it will be the
// `Borrowed` variant. Only with multiline strings on Windows will it
// ever actually clone the underlying string.
self.text.clone(),
self.token,
self.token.text_trimmed_range().start(),
),
Expand Down

0 comments on commit 985bf67

Please sign in to comment.