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

@ -4,6 +4,7 @@ use std::ops::Deref;
use bitflags::bitflags;
use rustc_hash::{FxBuildHasher, FxHashSet};
use ruff_python_ast::name::Name;
use ruff_python_ast::{
self as ast, BoolOp, CmpOp, ConversionFlag, Expr, ExprContext, FStringElement, FStringElements,
IpyEscapeKind, Number, Operator, UnaryOp,
@ -477,14 +478,11 @@ impl<'src> Parser<'src> {
let TokenValue::Name(name) = self.bump_value(TokenKind::Name) else {
unreachable!();
};
return ast::Identifier {
id: name.into_string(),
range,
};
return ast::Identifier { id: name, range };
}
if self.current_token_kind().is_soft_keyword() {
let id = self.src_text(range).to_string();
let id = Name::new(self.src_text(range));
self.bump_soft_keyword_as_name();
return ast::Identifier { id, range };
}
@ -499,7 +497,7 @@ impl<'src> Parser<'src> {
range,
);
let id = self.src_text(range).to_string();
let id = Name::new(self.src_text(range));
self.bump_any();
ast::Identifier { id, range }
} else {
@ -509,7 +507,7 @@ impl<'src> Parser<'src> {
);
ast::Identifier {
id: String::new(),
id: Name::empty(),
range: self.missing_node_range(),
}
}
@ -597,7 +595,7 @@ impl<'src> Parser<'src> {
);
Expr::Name(ast::ExprName {
range: self.missing_node_range(),
id: String::new(),
id: Name::empty(),
ctx: ExprContext::Invalid,
})
}
@ -719,7 +717,7 @@ impl<'src> Parser<'src> {
&parsed_expr,
);
ast::Identifier {
id: String::new(),
id: Name::empty(),
range: parsed_expr.range(),
}
};
@ -793,7 +791,7 @@ impl<'src> Parser<'src> {
value: Box::new(value),
slice: Box::new(Expr::Name(ast::ExprName {
range: slice_range,
id: String::new(),
id: Name::empty(),
ctx: ExprContext::Invalid,
})),
ctx: ExprContext::Load,