Use single lookup for leading, dangling, and trailing comments (#6589)

This commit is contained in:
Micha Reiser 2023-08-15 17:39:45 +02:00 committed by GitHub
parent 81b1176f99
commit 29c0b9f91c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
39 changed files with 319 additions and 387 deletions

View file

@ -106,7 +106,7 @@ use ruff_python_index::CommentRanges;
use ruff_python_trivia::PythonWhitespace;
use crate::comments::debug::{DebugComment, DebugComments};
use crate::comments::map::MultiMap;
use crate::comments::map::{LeadingDanglingTrailing, MultiMap};
use crate::comments::node_key::NodeRefEqualityKey;
use crate::comments::visitor::CommentsVisitor;
@ -405,13 +405,13 @@ impl<'a> Comments<'a> {
pub(crate) fn leading_dangling_trailing_comments<T>(
&self,
node: T,
) -> impl Iterator<Item = &SourceComment>
) -> LeadingDanglingTrailingComments
where
T: Into<AnyNodeRef<'a>>,
{
self.data
.comments
.parts(&NodeRefEqualityKey::from_ref(node.into()))
.leading_dangling_trailing(&NodeRefEqualityKey::from_ref(node.into()))
}
#[inline(always)]
@ -464,6 +464,8 @@ impl<'a> Comments<'a> {
}
}
pub(crate) type LeadingDanglingTrailingComments<'a> = LeadingDanglingTrailing<'a, SourceComment>;
#[derive(Debug, Default)]
struct CommentsData<'a> {
comments: CommentsMap<'a>,