mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-15 08:00:46 +00:00
Avoid cloning Name
when looking up function and class types (#14092)
This commit is contained in:
parent
a7a78f939c
commit
bc0586d922
5 changed files with 27 additions and 4 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -2638,6 +2638,7 @@ dependencies = [
|
||||||
"ruff_source_file",
|
"ruff_source_file",
|
||||||
"ruff_text_size",
|
"ruff_text_size",
|
||||||
"rustc-hash 2.0.0",
|
"rustc-hash 2.0.0",
|
||||||
|
"salsa",
|
||||||
"schemars",
|
"schemars",
|
||||||
"serde",
|
"serde",
|
||||||
]
|
]
|
||||||
|
|
|
@ -13,7 +13,7 @@ license = { workspace = true }
|
||||||
[dependencies]
|
[dependencies]
|
||||||
ruff_db = { workspace = true }
|
ruff_db = { workspace = true }
|
||||||
ruff_index = { workspace = true }
|
ruff_index = { workspace = true }
|
||||||
ruff_python_ast = { workspace = true }
|
ruff_python_ast = { workspace = true, features = ["salsa"] }
|
||||||
ruff_python_stdlib = { workspace = true }
|
ruff_python_stdlib = { workspace = true }
|
||||||
ruff_source_file = { workspace = true }
|
ruff_source_file = { workspace = true }
|
||||||
ruff_text_size = { workspace = true }
|
ruff_text_size = { workspace = true }
|
||||||
|
|
|
@ -856,7 +856,7 @@ impl<'db> TypeInferenceBuilder<'db> {
|
||||||
};
|
};
|
||||||
let function_ty = Type::FunctionLiteral(FunctionType::new(
|
let function_ty = Type::FunctionLiteral(FunctionType::new(
|
||||||
self.db,
|
self.db,
|
||||||
name.id.clone(),
|
&*name.id,
|
||||||
function_kind,
|
function_kind,
|
||||||
definition,
|
definition,
|
||||||
decorator_tys,
|
decorator_tys,
|
||||||
|
@ -965,7 +965,7 @@ impl<'db> TypeInferenceBuilder<'db> {
|
||||||
|
|
||||||
let class_ty = Type::ClassLiteral(ClassType::new(
|
let class_ty = Type::ClassLiteral(ClassType::new(
|
||||||
self.db,
|
self.db,
|
||||||
name.id.clone(),
|
&*name.id,
|
||||||
definition,
|
definition,
|
||||||
body_scope,
|
body_scope,
|
||||||
maybe_known_class,
|
maybe_known_class,
|
||||||
|
|
|
@ -26,13 +26,20 @@ is-macro = { workspace = true }
|
||||||
itertools = { workspace = true }
|
itertools = { workspace = true }
|
||||||
memchr = { workspace = true }
|
memchr = { workspace = true }
|
||||||
rustc-hash = { workspace = true }
|
rustc-hash = { workspace = true }
|
||||||
|
salsa = { workspace = true, optional = true }
|
||||||
schemars = { workspace = true, optional = true }
|
schemars = { workspace = true, optional = true }
|
||||||
serde = { workspace = true, optional = true }
|
serde = { workspace = true, optional = true }
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
schemars = ["dep:schemars"]
|
schemars = ["dep:schemars"]
|
||||||
cache = ["dep:ruff_cache", "dep:ruff_macros"]
|
cache = ["dep:ruff_cache", "dep:ruff_macros"]
|
||||||
serde = ["dep:serde", "ruff_text_size/serde", "dep:ruff_cache", "compact_str/serde"]
|
serde = [
|
||||||
|
"dep:serde",
|
||||||
|
"ruff_text_size/serde",
|
||||||
|
"dep:ruff_cache",
|
||||||
|
"compact_str/serde",
|
||||||
|
]
|
||||||
|
salsa = ["dep:salsa"]
|
||||||
|
|
||||||
[lints]
|
[lints]
|
||||||
workspace = true
|
workspace = true
|
||||||
|
|
|
@ -205,6 +205,21 @@ impl schemars::JsonSchema for Name {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "salsa")]
|
||||||
|
impl salsa::plumbing::interned::Lookup<Name> for &str {
|
||||||
|
fn hash<H: Hasher>(&self, h: &mut H) {
|
||||||
|
std::hash::Hash::hash(self, h);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn eq(&self, data: &Name) -> bool {
|
||||||
|
self == data
|
||||||
|
}
|
||||||
|
|
||||||
|
fn into_owned(self) -> Name {
|
||||||
|
Name::new(self)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// A representation of a qualified name, like `typing.List`.
|
/// A representation of a qualified name, like `typing.List`.
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||||
pub struct QualifiedName<'a>(SegmentsVec<'a>);
|
pub struct QualifiedName<'a>(SegmentsVec<'a>);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue