Skip to content

Commit

Permalink
highlighted_code_block: Take input text as &str
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
the-mikedavis committed Jul 26, 2023
1 parent dc63a3c commit c23edfb
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions helix-term/src/ui/lsp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ impl Component for SignatureHelp {
});

let sig_text = crate::ui::markdown::highlighted_code_block(
self.signature.clone(),
&self.signature,
&self.language,
Some(&cx.editor.theme),
Arc::clone(&self.config_loader),
Expand Down Expand Up @@ -109,7 +109,7 @@ impl Component for SignatureHelp {
let max_text_width = (viewport.0 - PADDING).min(120);

let signature_text = crate::ui::markdown::highlighted_code_block(
self.signature.clone(),
&self.signature,
&self.language,
None,
Arc::clone(&self.config_loader),
Expand Down
6 changes: 3 additions & 3 deletions helix-term/src/ui/markdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use helix_view::{
Theme,
};

fn styled_multiline_text<'a>(text: String, style: Style) -> Text<'a> {
fn styled_multiline_text<'a>(text: &str, style: Style) -> Text<'a> {
let spans: Vec<_> = text
.lines()
.map(|line| Span::styled(line.to_string(), style))
Expand All @@ -27,7 +27,7 @@ fn styled_multiline_text<'a>(text: String, style: Style) -> Text<'a> {
}

pub fn highlighted_code_block<'a>(
text: String,
text: &str,
language: &str,
theme: Option<&Theme>,
config_loader: Arc<syntax::Loader>,
Expand Down Expand Up @@ -267,7 +267,7 @@ impl Markdown {
CodeBlockKind::Indented => "",
};
let tui_text = highlighted_code_block(
text.to_string(),
&text,
language,
theme,
Arc::clone(&self.config_loader),
Expand Down
2 changes: 1 addition & 1 deletion helix-term/src/ui/prompt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ impl Prompt {
}
} else if let Some((language, loader)) = self.language.as_ref() {
let mut text: ui::text::Text = crate::ui::markdown::highlighted_code_block(
self.line.clone(),
&self.line,
language,
Some(&cx.editor.theme),
loader.clone(),
Expand Down

0 comments on commit c23edfb

Please sign in to comment.