avoid allocations during snippet rendering

pull/6250/head
Pascal Kuthe 2 years ago committed by Blaž Hrastnik
parent e91289fda1
commit cdec933523

@ -1,7 +1,7 @@
use std::borrow::Cow; use std::borrow::Cow;
use anyhow::{anyhow, Result}; use anyhow::{anyhow, Result};
use helix_core::{smallvec, SmallVec}; use helix_core::{smallvec, SmallVec, Tendril};
#[derive(Debug, PartialEq, Eq)] #[derive(Debug, PartialEq, Eq)]
pub enum CaseChange { pub enum CaseChange {
@ -57,10 +57,10 @@ pub fn parse(s: &str) -> Result<Snippet<'_>> {
fn render_elements( fn render_elements(
snippet_elements: &[SnippetElement<'_>], snippet_elements: &[SnippetElement<'_>],
insert: &mut String, insert: &mut Tendril,
offset: &mut usize, offset: &mut usize,
tabstops: &mut Vec<(usize, (usize, usize))>, tabstops: &mut Vec<(usize, (usize, usize))>,
newline_with_offset: &String, newline_with_offset: &str,
include_placeholer: bool, include_placeholer: bool,
) { ) {
use SnippetElement::*; use SnippetElement::*;
@ -121,10 +121,10 @@ fn render_elements(
#[allow(clippy::type_complexity)] // only used one time #[allow(clippy::type_complexity)] // only used one time
pub fn render( pub fn render(
snippet: &Snippet<'_>, snippet: &Snippet<'_>,
newline_with_offset: String, newline_with_offset: &str,
include_placeholer: bool, include_placeholer: bool,
) -> (String, Vec<SmallVec<[(usize, usize); 1]>>) { ) -> (Tendril, Vec<SmallVec<[(usize, usize); 1]>>) {
let mut insert = String::new(); let mut insert = Tendril::new();
let mut tabstops = Vec::new(); let mut tabstops = Vec::new();
let mut offset = 0; let mut offset = 0;
@ -133,7 +133,7 @@ pub fn render(
&mut insert, &mut insert,
&mut offset, &mut offset,
&mut tabstops, &mut tabstops,
&newline_with_offset, newline_with_offset,
include_placeholer, include_placeholer,
); );

Loading…
Cancel
Save