Reduce memory usage of Docstring struct (#16183)
This commit is contained in:
@@ -1645,6 +1645,16 @@ impl StringLiteral {
|
||||
flags: StringLiteralFlags::empty().with_invalid(),
|
||||
}
|
||||
}
|
||||
|
||||
/// The range of the string literal's contents.
|
||||
///
|
||||
/// This excludes any prefixes, opening quotes or closing quotes.
|
||||
pub fn content_range(&self) -> TextRange {
|
||||
TextRange::new(
|
||||
self.start() + self.flags.opener_len(),
|
||||
self.end() - self.flags.closer_len(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<StringLiteral> for Expr {
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
use ruff_text_size::TextSize;
|
||||
|
||||
use std::fmt;
|
||||
|
||||
/// Enumerations of the valid prefixes a string literal can have.
|
||||
@@ -33,6 +35,13 @@ impl StringLiteralPrefix {
|
||||
Self::Raw { uppercase: false } => "r",
|
||||
}
|
||||
}
|
||||
|
||||
pub const fn text_len(self) -> TextSize {
|
||||
match self {
|
||||
Self::Empty => TextSize::new(0),
|
||||
Self::Unicode | Self::Raw { .. } => TextSize::new(1),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for StringLiteralPrefix {
|
||||
|
||||
Reference in New Issue
Block a user