on master help sign in
avoid allocations during snippet rendering
commitcdec933523560f71c665469adc409d7ac0e06171 authorPascal Kuthe <pascal.kuthe@semimod.de> dateThu 9 Mar 2023, 22:17 (4 years ago) parente91289f
1 file changed+7−7
helix-lsp/src/snippet.rs+7−7
helix-lsp/src/snippet.rs+7−7
@@ -1,7 +1,7 @@
11use std::borrow::Cow;
22
33use anyhow::{anyhow, Result};
4−use helix_core::{smallvec, SmallVec};
4+use helix_core::{smallvec, SmallVec, Tendril};
55
66#[derive(Debug, PartialEq, Eq)]
77pub enum CaseChange {
@@ -57,10 +57,10 @@ pub fn parse(s: &str) -> Result<Snippet<'_>> {
5757
5858fn render_elements(
5959 snippet_elements: &[SnippetElement<'_>],
60− insert: &mut String,
60+ insert: &mut Tendril,
6161 offset: &mut usize,
6262 tabstops: &mut Vec<(usize, (usize, usize))>,
63− newline_with_offset: &String,
63+ newline_with_offset: &str,
6464 include_placeholer: bool,
6565) {
6666 use SnippetElement::*;
@@ -121,10 +121,10 @@ fn render_elements(
121121#[allow(clippy::type_complexity)] // only used one time
122122pub fn render(
123123 snippet: &Snippet<'_>,
124− newline_with_offset: String,
124+ newline_with_offset: &str,
125125 include_placeholer: bool,
126−) -> (String, Vec<SmallVec<[(usize, usize); 1]>>) {
127− let mut insert = String::new();
126+) -> (Tendril, Vec<SmallVec<[(usize, usize); 1]>>) {
127+ let mut insert = Tendril::new();
128128 let mut tabstops = Vec::new();
129129 let mut offset = 0;
130130
@@ -133,7 +133,7 @@ pub fn render(
133133 &mut insert,
134134 &mut offset,
135135 &mut tabstops,
136− &newline_with_offset,
136+ newline_with_offset,
137137 include_placeholer,
138138 );
139139