Skip to content

Commit

Permalink
avoid allocations during snippet rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
pascalkuthe authored and archseer committed Mar 10, 2023
1 parent e91289f commit cdec933
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions helix-lsp/src/snippet.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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::*;
Expand Down Expand Up @@ -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;

Expand All @@ -133,7 +133,7 @@ pub fn render(
&mut insert,
&mut offset,
&mut tabstops,
&newline_with_offset,
newline_with_offset,
include_placeholer,
);

Expand Down

0 comments on commit cdec933

Please sign in to comment.