From ed3e34c9ee8aad04d1b3af8e701da576a87b456c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1niel=20Buga?= Date: Sun, 15 May 2022 19:35:18 +0200 Subject: [PATCH] Only allocate once when toggling comments --- lapce-core/src/editor.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/lapce-core/src/editor.rs b/lapce-core/src/editor.rs index 7a37b920..6523e6e8 100644 --- a/lapce-core/src/editor.rs +++ b/lapce-core/src/editor.rs @@ -713,10 +713,8 @@ pub fn do_edit( ToggleLineComment => { let mut lines = HashSet::new(); let selection = cursor.edit_selection(buffer); - let comment_token = syntax - .map(|s| s.language.comment_token()) - .unwrap_or("//") - .to_string(); + let comment_token = + syntax.map(|s| s.language.comment_token()).unwrap_or("//"); let mut had_comment = true; let mut smallest_indent = usize::MAX; for region in selection.regions() { @@ -775,7 +773,7 @@ pub fn do_edit( selection.add_region(SelRegion::new(start, start, None)) } buffer.edit( - &[(&selection, &(comment_token + " "))], + &[(&selection, &format!("{comment_token} "))], EditType::InsertChars, ) };