on master help sign in
avoid allocations during snippet rendering
cdec933Pascal Kuthe
helix-lsp/src/snippet.rs+7−7
@@ -1,7 +1,7 @@
1use std::borrow::Cow;
1use std::borrow::Cow;
2
2
3use anyhow::{anyhow, Result};
3use anyhow::{anyhow, Result};
4−use helix_core::{smallvec, SmallVec};
4+use helix_core::{smallvec, SmallVec, Tendril};
5
5
6#[derive(Debug, PartialEq, Eq)]
6#[derive(Debug, PartialEq, Eq)]
7pub enum CaseChange {
7pub enum CaseChange {
@@ -57,10 +57,10 @@ pub fn parse(s: &str) -> Result<Snippet<'_>> {
57
57
58fn render_elements(
58fn render_elements(
59 snippet_elements: &[SnippetElement<'_>],
59 snippet_elements: &[SnippetElement<'_>],
60− insert: &mut String,
60+ insert: &mut Tendril,
61 offset: &mut usize,
61 offset: &mut usize,
62 tabstops: &mut Vec<(usize, (usize, usize))>,
62 tabstops: &mut Vec<(usize, (usize, usize))>,
63− newline_with_offset: &String,
63+ newline_with_offset: &str,
64 include_placeholer: bool,
64 include_placeholer: bool,
65) {
65) {
66 use SnippetElement::*;
66 use SnippetElement::*;
@@ -121,10 +121,10 @@ fn render_elements(
121#[allow(clippy::type_complexity)] // only used one time
121#[allow(clippy::type_complexity)] // only used one time
122pub fn render(
122pub fn render(
123 snippet: &Snippet<'_>,
123 snippet: &Snippet<'_>,
124− newline_with_offset: String,
124+ newline_with_offset: &str,
125 include_placeholer: bool,
125 include_placeholer: bool,
126−) -> (String, Vec<SmallVec<[(usize, usize); 1]>>) {
126+) -> (Tendril, Vec<SmallVec<[(usize, usize); 1]>>) {
127− let mut insert = String::new();
127+ let mut insert = Tendril::new();
128 let mut tabstops = Vec::new();
128 let mut tabstops = Vec::new();
129 let mut offset = 0;
129 let mut offset = 0;
130
130
@@ -133,7 +133,7 @@ pub fn render(
133 &mut insert,
133 &mut insert,
134 &mut offset,
134 &mut offset,
135 &mut tabstops,
135 &mut tabstops,
136− &newline_with_offset,
136+ newline_with_offset,
137 include_placeholer,
137 include_placeholer,
138 );
138 );
139
139