mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-04 10:48:32 +00:00
Reduce memory usage of Docstring
struct (#16183)
This commit is contained in:
parent
93aff36147
commit
61fef0a64a
15 changed files with 151 additions and 90 deletions
|
@ -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 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue