Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit b9c5d23

Browse files
committed
Simplify a bit
1 parent cff209f commit b9c5d23

File tree

1 file changed

+13
-15
lines changed

1 file changed

+13
-15
lines changed

crates/mbe/src/syntax_bridge.rs

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -484,12 +484,12 @@ impl Convertor {
484484
fn new(
485485
node: &SyntaxNode,
486486
global_offset: TextSize,
487-
replace: FxHashMap<SyntaxNode, Vec<SyntheticToken>>,
488-
append: FxHashMap<SyntaxNode, Vec<SyntheticToken>>,
487+
mut replace: FxHashMap<SyntaxNode, Vec<SyntheticToken>>,
488+
mut append: FxHashMap<SyntaxNode, Vec<SyntheticToken>>,
489489
) -> Convertor {
490490
let range = node.text_range();
491491
let mut preorder = node.preorder_with_tokens();
492-
let (first, synthetic) = Self::next_token(&mut preorder, &replace, &append);
492+
let (first, synthetic) = Self::next_token(&mut preorder, &mut replace, &mut append);
493493
Convertor {
494494
id_alloc: { TokenIdAlloc { map: TokenMap::default(), global_offset, next_id: 0 } },
495495
current: first,
@@ -504,19 +504,18 @@ impl Convertor {
504504

505505
fn next_token(
506506
preorder: &mut PreorderWithTokens,
507-
replace: &FxHashMap<SyntaxNode, Vec<SyntheticToken>>,
508-
append: &FxHashMap<SyntaxNode, Vec<SyntheticToken>>,
507+
replace: &mut FxHashMap<SyntaxNode, Vec<SyntheticToken>>,
508+
append: &mut FxHashMap<SyntaxNode, Vec<SyntheticToken>>,
509509
) -> (Option<SyntaxToken>, Vec<SyntheticToken>) {
510510
while let Some(ev) = preorder.next() {
511511
let ele = match ev {
512512
WalkEvent::Enter(ele) => ele,
513513
WalkEvent::Leave(SyntaxElement::Node(node)) => {
514-
if let Some(v) = append.get(&node) {
514+
if let Some(mut v) = append.remove(&node) {
515515
eprintln!("after {:?}, appending {:?}", node, v);
516516
if !v.is_empty() {
517-
let mut reversed = v.clone();
518-
reversed.reverse();
519-
return (None, reversed);
517+
v.reverse();
518+
return (None, v);
520519
}
521520
}
522521
continue;
@@ -526,13 +525,12 @@ impl Convertor {
526525
match ele {
527526
SyntaxElement::Token(t) => return (Some(t), Vec::new()),
528527
SyntaxElement::Node(node) => {
529-
if let Some(v) = replace.get(&node) {
528+
if let Some(mut v) = replace.remove(&node) {
530529
preorder.skip_subtree();
531530
eprintln!("replacing {:?} by {:?}", node, v);
532531
if !v.is_empty() {
533-
let mut reversed = v.clone();
534-
reversed.reverse();
535-
return (None, reversed);
532+
v.reverse();
533+
return (None, v);
536534
}
537535
}
538536
}
@@ -603,7 +601,7 @@ impl TokenConvertor for Convertor {
603601
if let Some(synth_token) = self.current_synthetic.pop() {
604602
if self.current_synthetic.is_empty() {
605603
let (new_current, new_synth) =
606-
Self::next_token(&mut self.preorder, &self.replace, &self.append);
604+
Self::next_token(&mut self.preorder, &mut self.replace, &mut self.append);
607605
self.current = new_current;
608606
self.current_synthetic = new_synth;
609607
}
@@ -616,7 +614,7 @@ impl TokenConvertor for Convertor {
616614
return None;
617615
}
618616
let (new_current, new_synth) =
619-
Self::next_token(&mut self.preorder, &self.replace, &self.append);
617+
Self::next_token(&mut self.preorder, &mut self.replace, &mut self.append);
620618
self.current = new_current;
621619
self.current_synthetic = new_synth;
622620
let token = if curr.kind().is_punct() {

0 commit comments

Comments
 (0)