aboutsummaryrefslogtreecommitdiff
path: root/helix-lsp/src
diff options
context:
space:
mode:
authorPascal Kuthe2023-03-09 21:17:12 +0000
committerBlaž Hrastnik2023-03-10 07:54:17 +0000
commitcdec933523560f71c665469adc409d7ac0e06171 (patch)
treecca73485db935ff4cef0ae3e800fc54291a8ae2f /helix-lsp/src
parente91289fda1c81bc3f3cc32735a1b6841e6df55a5 (diff)
avoid allocations during snippet rendering
Diffstat (limited to 'helix-lsp/src')
-rw-r--r--helix-lsp/src/snippet.rs14
1 files changed, 7 insertions, 7 deletions
diff --git a/helix-lsp/src/snippet.rs b/helix-lsp/src/snippet.rs
index b27077e7..4713ad8b 100644
--- a/helix-lsp/src/snippet.rs
+++ b/helix-lsp/src/snippet.rs
@@ -1,7 +1,7 @@
use std::borrow::Cow;
use anyhow::{anyhow, Result};
-use helix_core::{smallvec, SmallVec};
+use helix_core::{smallvec, SmallVec, Tendril};
#[derive(Debug, PartialEq, Eq)]
pub enum CaseChange {
@@ -57,10 +57,10 @@ pub fn parse(s: &str) -> Result<Snippet<'_>> {
fn render_elements(
snippet_elements: &[SnippetElement<'_>],
- insert: &mut String,
+ insert: &mut Tendril,
offset: &mut usize,
tabstops: &mut Vec<(usize, (usize, usize))>,
- newline_with_offset: &String,
+ newline_with_offset: &str,
include_placeholer: bool,
) {
use SnippetElement::*;
@@ -121,10 +121,10 @@ fn render_elements(
#[allow(clippy::type_complexity)] // only used one time
pub fn render(
snippet: &Snippet<'_>,
- newline_with_offset: String,
+ newline_with_offset: &str,
include_placeholer: bool,
-) -> (String, Vec<SmallVec<[(usize, usize); 1]>>) {
- let mut insert = String::new();
+) -> (Tendril, Vec<SmallVec<[(usize, usize); 1]>>) {
+ let mut insert = Tendril::new();
let mut tabstops = Vec::new();
let mut offset = 0;
@@ -133,7 +133,7 @@ pub fn render(
&mut insert,
&mut offset,
&mut tabstops,
- &newline_with_offset,
+ newline_with_offset,
include_placeholer,
);