mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-03 18:28:24 +00:00
Reduce Result<Tok, LexicalError>
size by using Box<str>
instead of String
(#9885)
This commit is contained in:
parent
9027169125
commit
fe7d965334
22 changed files with 454 additions and 425 deletions
|
@ -631,7 +631,7 @@ pub struct ComparableStringLiteral<'a> {
|
|||
impl<'a> From<&'a ast::StringLiteral> for ComparableStringLiteral<'a> {
|
||||
fn from(string_literal: &'a ast::StringLiteral) -> Self {
|
||||
Self {
|
||||
value: string_literal.value.as_str(),
|
||||
value: &string_literal.value,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1089,10 +1089,7 @@ impl<'a> From<&'a ast::Expr> for ComparableExpr<'a> {
|
|||
kind,
|
||||
value,
|
||||
range: _,
|
||||
}) => Self::IpyEscapeCommand(ExprIpyEscapeCommand {
|
||||
kind: *kind,
|
||||
value: value.as_str(),
|
||||
}),
|
||||
}) => Self::IpyEscapeCommand(ExprIpyEscapeCommand { kind: *kind, value }),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1537,10 +1534,7 @@ impl<'a> From<&'a ast::Stmt> for ComparableStmt<'a> {
|
|||
kind,
|
||||
value,
|
||||
range: _,
|
||||
}) => Self::IpyEscapeCommand(StmtIpyEscapeCommand {
|
||||
kind: *kind,
|
||||
value: value.as_str(),
|
||||
}),
|
||||
}) => Self::IpyEscapeCommand(StmtIpyEscapeCommand { kind: *kind, value }),
|
||||
ast::Stmt::Expr(ast::StmtExpr { value, range: _ }) => Self::Expr(StmtExpr {
|
||||
value: value.into(),
|
||||
}),
|
||||
|
|
|
@ -160,7 +160,7 @@ pub enum Stmt {
|
|||
pub struct StmtIpyEscapeCommand {
|
||||
pub range: TextRange,
|
||||
pub kind: IpyEscapeKind,
|
||||
pub value: String,
|
||||
pub value: Box<str>,
|
||||
}
|
||||
|
||||
impl From<StmtIpyEscapeCommand> for Stmt {
|
||||
|
@ -671,7 +671,7 @@ impl Expr {
|
|||
pub struct ExprIpyEscapeCommand {
|
||||
pub range: TextRange,
|
||||
pub kind: IpyEscapeKind,
|
||||
pub value: String,
|
||||
pub value: Box<str>,
|
||||
}
|
||||
|
||||
impl From<ExprIpyEscapeCommand> for Expr {
|
||||
|
@ -1384,7 +1384,7 @@ impl Default for StringLiteralValueInner {
|
|||
#[derive(Clone, Debug, Default, PartialEq)]
|
||||
pub struct StringLiteral {
|
||||
pub range: TextRange,
|
||||
pub value: String,
|
||||
pub value: Box<str>,
|
||||
pub unicode: bool,
|
||||
}
|
||||
|
||||
|
@ -1398,7 +1398,7 @@ impl Deref for StringLiteral {
|
|||
type Target = str;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
self.value.as_str()
|
||||
&self.value
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1426,14 +1426,16 @@ struct ConcatenatedStringLiteral {
|
|||
/// Each string literal that makes up the concatenated string.
|
||||
strings: Vec<StringLiteral>,
|
||||
/// The concatenated string value.
|
||||
value: OnceCell<String>,
|
||||
value: OnceCell<Box<str>>,
|
||||
}
|
||||
|
||||
impl ConcatenatedStringLiteral {
|
||||
/// Extracts a string slice containing the entire concatenated string.
|
||||
fn to_str(&self) -> &str {
|
||||
self.value
|
||||
.get_or_init(|| self.strings.iter().map(StringLiteral::as_str).collect())
|
||||
self.value.get_or_init(|| {
|
||||
let concatenated: String = self.strings.iter().map(StringLiteral::as_str).collect();
|
||||
concatenated.into_boxed_str()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue