on master help sign in
highlighted_code_block: Take input text as &str

This removes a handful of allocations for functions calling into the function, which is nice because the prompt may call this function on every keypress.

commit953073a679dfe8ae4aff86e8a9bff680d14a5523 authorMichael Davis <mcarsondavis@gmail.com> dateWed 26 Jul 2023, 10:26 (3 years ago) parent98ef05d
3 files changed+6−6
helix-term/src/ui/lsp.rs+2−2 helix-term/src/ui/markdown.rs+3−3 helix-term/src/ui/prompt.rs+1−1
helix-term/src/ui/lsp.rs+2−2
@@ -62,7 +62,7 @@ impl Component for SignatureHelp {
6262 });
6363
6464 let sig_text = crate::ui::markdown::highlighted_code_block(
65− self.signature.clone(),
65+ &self.signature,
6666 &self.language,
6767 Some(&cx.editor.theme),
6868 Arc::clone(&self.config_loader),
@@ -109,7 +109,7 @@ impl Component for SignatureHelp {
109109 let max_text_width = (viewport.0 - PADDING).min(120);
110110
111111 let signature_text = crate::ui::markdown::highlighted_code_block(
112− self.signature.clone(),
112+ &self.signature,
113113 &self.language,
114114 None,
115115 Arc::clone(&self.config_loader),
helix-term/src/ui/markdown.rs+3−3
@@ -17,7 +17,7 @@ use helix_view::{
1717 Theme,
1818};
1919
20−fn styled_multiline_text<'a>(text: String, style: Style) -> Text<'a> {
20+fn styled_multiline_text<'a>(text: &str, style: Style) -> Text<'a> {
2121 let spans: Vec<_> = text
2222 .lines()
2323 .map(|line| Span::styled(line.to_string(), style))
@@ -27,7 +27,7 @@ fn styled_multiline_text<'a>(text: String, style: Style) -> Text<'a> {
2727}
2828
2929pub fn highlighted_code_block<'a>(
30− text: String,
30+ text: &str,
3131 language: &str,
3232 theme: Option<&Theme>,
3333 config_loader: Arc<syntax::Loader>,
@@ -267,7 +267,7 @@ impl Markdown {
267267 CodeBlockKind::Indented => "",
268268 };
269269 let tui_text = highlighted_code_block(
270− text.to_string(),
270+ &text,
271271 language,
272272 theme,
273273 Arc::clone(&self.config_loader),
helix-term/src/ui/prompt.rs+1−1
@@ -476,7 +476,7 @@ impl Prompt {
476476 }
477477 } else if let Some((language, loader)) = self.language.as_ref() {
478478 let mut text: ui::text::Text = crate::ui::markdown::highlighted_code_block(
479− self.line.clone(),
479+ &self.line,
480480 language,
481481 Some(&cx.editor.theme),
482482 loader.clone(),