Use CompactString for Identifier (#12101)

This commit is contained in:
Micha Reiser 2024-07-01 10:06:02 +02:00 committed by GitHub
parent db6ee74cbe
commit 5109b50bb3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
474 changed files with 4953 additions and 4776 deletions

View file

@ -12,6 +12,7 @@ use itertools::Itertools;
use ruff_text_size::{Ranged, TextLen, TextRange, TextSize};
use crate::name::Name;
use crate::{
int,
str::Quote,
@ -1762,12 +1763,6 @@ impl PartialEq<str> for StringLiteralValue {
}
}
impl PartialEq<String> for StringLiteralValue {
fn eq(&self, other: &String) -> bool {
self == other.as_str()
}
}
impl fmt::Display for StringLiteralValue {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(self.to_str())
@ -2740,10 +2735,16 @@ impl From<ExprStarred> for Expr {
#[derive(Clone, Debug, PartialEq)]
pub struct ExprName {
pub range: TextRange,
pub id: String,
pub id: Name,
pub ctx: ExprContext,
}
impl ExprName {
pub fn id(&self) -> &Name {
&self.id
}
}
impl From<ExprName> for Expr {
fn from(payload: ExprName) -> Self {
Expr::Name(payload)
@ -3763,19 +3764,23 @@ impl IpyEscapeKind {
/// ```
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct Identifier {
pub id: String,
pub id: Name,
pub range: TextRange,
}
impl Identifier {
#[inline]
pub fn new(id: impl Into<String>, range: TextRange) -> Self {
pub fn new(id: impl Into<Name>, range: TextRange) -> Self {
Self {
id: id.into(),
range,
}
}
pub fn id(&self) -> &Name {
&self.id
}
pub fn is_valid(&self) -> bool {
!self.id.is_empty()
}
@ -3798,7 +3803,7 @@ impl PartialEq<str> for Identifier {
impl PartialEq<String> for Identifier {
#[inline]
fn eq(&self, other: &String) -> bool {
&self.id == other
self.id == other
}
}
@ -3817,22 +3822,15 @@ impl AsRef<str> for Identifier {
}
}
impl AsRef<String> for Identifier {
#[inline]
fn as_ref(&self) -> &String {
&self.id
}
}
impl std::fmt::Display for Identifier {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
std::fmt::Display::fmt(&self.id, f)
}
}
impl From<Identifier> for String {
impl From<Identifier> for Name {
#[inline]
fn from(identifier: Identifier) -> String {
fn from(identifier: Identifier) -> Name {
identifier.id
}
}