From 464af68ec56b1b35151acc3b53eea3d3d67e03d3 Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Tue, 14 Apr 2020 01:23:33 +0800 Subject: [PATCH] Remove format from syntax_bridge hot path --- crates/ra_mbe/src/syntax_bridge.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/crates/ra_mbe/src/syntax_bridge.rs b/crates/ra_mbe/src/syntax_bridge.rs index 9fb5cb0583..31e9b22e7d 100644 --- a/crates/ra_mbe/src/syntax_bridge.rs +++ b/crates/ra_mbe/src/syntax_bridge.rs @@ -607,12 +607,13 @@ impl<'a> TreeSink for TtTreeSink<'a> { let text: SmolStr = match self.cursor.token_tree() { Some(tt::TokenTree::Leaf(leaf)) => { // Mark the range if needed - let id = match leaf { - tt::Leaf::Ident(ident) => ident.id, - tt::Leaf::Punct(punct) => punct.id, - tt::Leaf::Literal(lit) => lit.id, + let (text, id) = match leaf { + tt::Leaf::Ident(ident) => (ident.text.clone(), ident.id), + tt::Leaf::Punct(punct) => { + (SmolStr::new_inline_from_ascii(1, &[punct.char as u8]), punct.id) + } + tt::Leaf::Literal(lit) => (lit.text.clone(), lit.id), }; - let text = SmolStr::new(format!("{}", leaf)); let range = TextRange::offset_len(self.text_pos, TextUnit::of_str(&text)); self.token_map.insert(id, range); self.cursor = self.cursor.bump();