diff options
| author | Dezhi Wu <wu543065657@163.com> | 2021-10-26 20:55:58 +0800 |
|---|---|---|
| committer | Dezhi Wu <wu543065657@163.com> | 2021-10-26 20:59:48 +0800 |
| commit | 31af94b73ae98e979f6e4b11a01d2a1c742f1bf4 (patch) | |
| tree | f3bf9be636505f3e38f87a6ce8ffe67e88fa597c | |
| parent | b7b9cd5e678ca824f0b12d0b8c44107587ffd051 (diff) | |
| download | rust-31af94b73ae98e979f6e4b11a01d2a1c742f1bf4.tar.gz rust-31af94b73ae98e979f6e4b11a01d2a1c742f1bf4.zip | |
perf: avoid allocating by just slicing.
Signed-off-by: Dezhi Wu <wu543065657@163.com>
| -rw-r--r-- | crates/rust-analyzer/src/markdown.rs | 13 |
1 files changed, 5 insertions, 8 deletions
diff --git a/crates/rust-analyzer/src/markdown.rs b/crates/rust-analyzer/src/markdown.rs index 9ffd085b0c3..59c904f86e7 100644 --- a/crates/rust-analyzer/src/markdown.rs +++ b/crates/rust-analyzer/src/markdown.rs @@ -1,6 +1,4 @@ //! Transforms markdown -use std::borrow::Cow; - use ide_db::helpers::rust_doc::is_rust_fence; const RUSTDOC_FENCE: &str = "```"; @@ -10,9 +8,8 @@ pub(crate) fn format_docs(src: &str) -> String { let mut in_code_block = false; let mut is_rust = false; - for line in src.lines() { - let mut line = Cow::from(line); - if in_code_block && is_rust && code_line_ignored_by_rustdoc(&line) { + for mut line in src.lines() { + if in_code_block && is_rust && code_line_ignored_by_rustdoc(line) { continue; } @@ -23,15 +20,15 @@ pub(crate) fn format_docs(src: &str) -> String { is_rust = is_rust_fence(header); if is_rust { - line = Cow::Borrowed("```rust"); + line = "```rust"; } } } if in_code_block { - let trimmed = line.trim(); + let trimmed = line.trim_start(); if trimmed.starts_with("##") { - line = Cow::Owned(line.replacen("##", "#", 1)); + line = &trimmed[1..]; } } |
