mirror of https://github.com/astral-sh/ruff
Inline NodeKey construction and avoid `AnyNodeRef`
This commit is contained in:
parent
f873d2ac12
commit
82f33db5e6
|
|
@ -1,4 +1,4 @@
|
||||||
use ruff_python_ast::{AnyNodeRef, NodeKind};
|
use ruff_python_ast::{AnyNodeRef, AstNode, NodeKind};
|
||||||
use ruff_text_size::{Ranged, TextRange};
|
use ruff_text_size::{Ranged, TextRange};
|
||||||
|
|
||||||
/// Compact key for a node for use in a hash map.
|
/// Compact key for a node for use in a hash map.
|
||||||
|
|
@ -11,7 +11,19 @@ pub(super) struct NodeKey {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl NodeKey {
|
impl NodeKey {
|
||||||
pub(super) fn from_node<'a, N>(node: N) -> Self
|
#[inline]
|
||||||
|
pub(super) fn from_node<'a, N>(node: &N) -> Self
|
||||||
|
where
|
||||||
|
N: AstNode,
|
||||||
|
{
|
||||||
|
NodeKey {
|
||||||
|
kind: node.kind(),
|
||||||
|
range: node.range(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub(super) fn from_ref<'a, N>(node: N) -> Self
|
||||||
where
|
where
|
||||||
N: Into<AnyNodeRef<'a>>,
|
N: Into<AnyNodeRef<'a>>,
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -197,12 +197,14 @@ pub(crate) mod node_key {
|
||||||
pub(crate) struct ExpressionNodeKey(NodeKey);
|
pub(crate) struct ExpressionNodeKey(NodeKey);
|
||||||
|
|
||||||
impl From<ast::ExpressionRef<'_>> for ExpressionNodeKey {
|
impl From<ast::ExpressionRef<'_>> for ExpressionNodeKey {
|
||||||
|
#[inline]
|
||||||
fn from(value: ast::ExpressionRef<'_>) -> Self {
|
fn from(value: ast::ExpressionRef<'_>) -> Self {
|
||||||
Self(NodeKey::from_node(value))
|
Self(NodeKey::from_ref(value))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<&ast::Expr> for ExpressionNodeKey {
|
impl From<&ast::Expr> for ExpressionNodeKey {
|
||||||
|
#[inline]
|
||||||
fn from(value: &ast::Expr) -> Self {
|
fn from(value: &ast::Expr) -> Self {
|
||||||
Self(NodeKey::from_node(value))
|
Self(NodeKey::from_node(value))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue