mirror of https://github.com/astral-sh/ruff
[ty] Use `CompactStr` for `StringLiteralType` (#21497)
This commit is contained in:
parent
d9fc0f08b4
commit
58fa1d71b6
|
|
@ -1,3 +1,4 @@
|
||||||
|
use compact_str::{CompactString, ToCompactString};
|
||||||
use infer::nearest_enclosing_class;
|
use infer::nearest_enclosing_class;
|
||||||
use itertools::{Either, Itertools};
|
use itertools::{Either, Itertools};
|
||||||
use ruff_db::parsed::parsed_module;
|
use ruff_db::parsed::parsed_module;
|
||||||
|
|
@ -7497,7 +7498,7 @@ impl<'db> Type<'db> {
|
||||||
Type::SpecialForm(special_form) => Type::string_literal(db, special_form.repr()),
|
Type::SpecialForm(special_form) => Type::string_literal(db, special_form.repr()),
|
||||||
Type::KnownInstance(known_instance) => Type::StringLiteral(StringLiteralType::new(
|
Type::KnownInstance(known_instance) => Type::StringLiteral(StringLiteralType::new(
|
||||||
db,
|
db,
|
||||||
known_instance.repr(db).to_string().into_boxed_str(),
|
known_instance.repr(db).to_compact_string(),
|
||||||
)),
|
)),
|
||||||
// TODO: handle more complex types
|
// TODO: handle more complex types
|
||||||
_ => KnownClass::Str.to_instance(db),
|
_ => KnownClass::Str.to_instance(db),
|
||||||
|
|
@ -7519,7 +7520,7 @@ impl<'db> Type<'db> {
|
||||||
Type::SpecialForm(special_form) => Type::string_literal(db, special_form.repr()),
|
Type::SpecialForm(special_form) => Type::string_literal(db, special_form.repr()),
|
||||||
Type::KnownInstance(known_instance) => Type::StringLiteral(StringLiteralType::new(
|
Type::KnownInstance(known_instance) => Type::StringLiteral(StringLiteralType::new(
|
||||||
db,
|
db,
|
||||||
known_instance.repr(db).to_string().into_boxed_str(),
|
known_instance.repr(db).to_compact_string(),
|
||||||
)),
|
)),
|
||||||
// TODO: handle more complex types
|
// TODO: handle more complex types
|
||||||
_ => KnownClass::Str.to_instance(db),
|
_ => KnownClass::Str.to_instance(db),
|
||||||
|
|
@ -12388,7 +12389,7 @@ impl<'db> IntersectionType<'db> {
|
||||||
#[derive(PartialOrd, Ord)]
|
#[derive(PartialOrd, Ord)]
|
||||||
pub struct StringLiteralType<'db> {
|
pub struct StringLiteralType<'db> {
|
||||||
#[returns(deref)]
|
#[returns(deref)]
|
||||||
value: Box<str>,
|
value: CompactString,
|
||||||
}
|
}
|
||||||
|
|
||||||
// The Salsa heap is tracked separately.
|
// The Salsa heap is tracked separately.
|
||||||
|
|
|
||||||
|
|
@ -436,7 +436,7 @@ where
|
||||||
.with_failure_code(server::ErrorCode::InternalError)
|
.with_failure_code(server::ErrorCode::InternalError)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sends back a response to the server, but only if the request wasn't cancelled.
|
/// Sends back a response to the client, but only if the request wasn't cancelled.
|
||||||
fn respond<Req>(
|
fn respond<Req>(
|
||||||
id: &RequestId,
|
id: &RequestId,
|
||||||
result: Result<<<Req as RequestHandler>::RequestType as Request>::Result>,
|
result: Result<<<Req as RequestHandler>::RequestType as Request>::Result>,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue