@@ -414,7 +414,7 @@ trait TokenConvertor {
414
414
fn id_alloc ( & mut self ) -> & mut TokenIdAlloc ;
415
415
}
416
416
417
- impl < ' a > SrcToken for ( RawToken , & ' a str ) {
417
+ impl < ' a > SrcToken for ( & ' a RawToken , & ' a str ) {
418
418
fn kind ( & self ) -> SyntaxKind {
419
419
self . 0 . kind
420
420
}
@@ -431,7 +431,7 @@ impl<'a> SrcToken for (RawToken, &'a str) {
431
431
impl RawConvertor < ' _ > { }
432
432
433
433
impl < ' a > TokenConvertor for RawConvertor < ' a > {
434
- type Token = ( RawToken , & ' a str ) ;
434
+ type Token = ( & ' a RawToken , & ' a str ) ;
435
435
436
436
fn convert_doc_comment ( & self , token : & Self :: Token ) -> Option < Vec < tt:: TokenTree > > {
437
437
convert_doc_comment ( & doc_comment ( token. 1 ) )
@@ -442,11 +442,11 @@ impl<'a> TokenConvertor for RawConvertor<'a> {
442
442
let range = TextRange :: at ( self . offset , token. len ) ;
443
443
self . offset += token. len ;
444
444
445
- Some ( ( ( * token, & self . text [ range] ) , range) )
445
+ Some ( ( ( token, & self . text [ range] ) , range) )
446
446
}
447
447
448
448
fn peek ( & self ) -> Option < Self :: Token > {
449
- let token = self . inner . as_slice ( ) . get ( 0 ) . cloned ( ) ;
449
+ let token = self . inner . as_slice ( ) . get ( 0 ) ;
450
450
451
451
token. map ( |it| {
452
452
let range = TextRange :: at ( self . offset , it. len ) ;
@@ -601,17 +601,16 @@ impl<'a> TtTreeSink<'a> {
601
601
}
602
602
}
603
603
604
- fn delim_to_str ( d : Option < tt:: DelimiterKind > , closing : bool ) -> SmolStr {
604
+ fn delim_to_str ( d : Option < tt:: DelimiterKind > , closing : bool ) -> & ' static str {
605
605
let texts = match d {
606
606
Some ( tt:: DelimiterKind :: Parenthesis ) => "()" ,
607
607
Some ( tt:: DelimiterKind :: Brace ) => "{}" ,
608
608
Some ( tt:: DelimiterKind :: Bracket ) => "[]" ,
609
- None => return "" . into ( ) ,
609
+ None => return "" ,
610
610
} ;
611
611
612
612
let idx = closing as usize ;
613
- let text = & texts[ idx..texts. len ( ) - ( 1 - idx) ] ;
614
- text. into ( )
613
+ & texts[ idx..texts. len ( ) - ( 1 - idx) ]
615
614
}
616
615
617
616
impl < ' a > TreeSink for TtTreeSink < ' a > {
@@ -626,22 +625,25 @@ impl<'a> TreeSink for TtTreeSink<'a> {
626
625
627
626
let mut last = self . cursor ;
628
627
for _ in 0 ..n_tokens {
628
+ let tmp_str: SmolStr ;
629
629
if self . cursor . eof ( ) {
630
630
break ;
631
631
}
632
632
last = self . cursor ;
633
- let text: SmolStr = match self . cursor . token_tree ( ) {
633
+ let text: & str = match self . cursor . token_tree ( ) {
634
634
Some ( tt:: TokenTree :: Leaf ( leaf) ) => {
635
635
// Mark the range if needed
636
636
let ( text, id) = match leaf {
637
- tt:: Leaf :: Ident ( ident) => ( ident. text . clone ( ) , ident. id ) ,
637
+ tt:: Leaf :: Ident ( ident) => ( & ident. text , ident. id ) ,
638
638
tt:: Leaf :: Punct ( punct) => {
639
639
assert ! ( punct. char . is_ascii( ) ) ;
640
640
let char = & ( punct. char as u8 ) ;
641
- let text = std:: str:: from_utf8 ( std:: slice:: from_ref ( char) ) . unwrap ( ) ;
642
- ( SmolStr :: new_inline ( text) , punct. id )
641
+ tmp_str = SmolStr :: new_inline (
642
+ std:: str:: from_utf8 ( std:: slice:: from_ref ( char) ) . unwrap ( ) ,
643
+ ) ;
644
+ ( & tmp_str, punct. id )
643
645
}
644
- tt:: Leaf :: Literal ( lit) => ( lit. text . clone ( ) , lit. id ) ,
646
+ tt:: Leaf :: Literal ( lit) => ( & lit. text , lit. id ) ,
645
647
} ;
646
648
let range = TextRange :: at ( self . text_pos , TextSize :: of ( text. as_str ( ) ) ) ;
647
649
self . token_map . insert ( id, range) ;
@@ -672,7 +674,7 @@ impl<'a> TreeSink for TtTreeSink<'a> {
672
674
}
673
675
} ;
674
676
self . buf += & text;
675
- self . text_pos += TextSize :: of ( text. as_str ( ) ) ;
677
+ self . text_pos += TextSize :: of ( text) ;
676
678
}
677
679
678
680
let text = SmolStr :: new ( self . buf . as_str ( ) ) ;
0 commit comments