fix: Fix token downmapping being quadratic

This commit is contained in:
Lukas Wirth 2023-12-08 15:26:38 +01:00
parent bc9c952b6d
commit 5d951a6a46
2 changed files with 167 additions and 134 deletions

View file

@ -605,8 +605,8 @@ pub struct ExpansionInfo {
}
impl ExpansionInfo {
pub fn expanded(&self) -> InFile<SyntaxNode> {
self.expanded.clone().into()
pub fn expanded(&self) -> InMacroFile<SyntaxNode> {
self.expanded.clone()
}
pub fn call_node(&self) -> Option<InFile<SyntaxNode>> {
@ -617,13 +617,13 @@ impl ExpansionInfo {
pub fn map_range_down<'a>(
&'a self,
span: SpanData,
) -> Option<impl Iterator<Item = InMacroFile<SyntaxToken>> + 'a> {
) -> Option<InMacroFile<impl Iterator<Item = SyntaxToken> + 'a>> {
let tokens = self
.exp_map
.ranges_with_span(span)
.flat_map(move |range| self.expanded.value.covering_element(range).into_token());
Some(tokens.map(move |token| InMacroFile::new(self.expanded.file_id, token)))
Some(InMacroFile::new(self.expanded.file_id, tokens))
}
/// Looks up the span at the given offset.