Skip to content

Commit 31af94b

Browse files
committed
perf: avoid allocating by just slicing.
Signed-off-by: Dezhi Wu <wu543065657@163.com>
1 parent b7b9cd5 commit 31af94b

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

crates/rust-analyzer/src/markdown.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
//! Transforms markdown
2-
use std::borrow::Cow;
3-
42
use ide_db::helpers::rust_doc::is_rust_fence;
53

64
const RUSTDOC_FENCE: &str = "```";
@@ -10,9 +8,8 @@ pub(crate) fn format_docs(src: &str) -> String {
108
let mut in_code_block = false;
119
let mut is_rust = false;
1210

13-
for line in src.lines() {
14-
let mut line = Cow::from(line);
15-
if in_code_block && is_rust && code_line_ignored_by_rustdoc(&line) {
11+
for mut line in src.lines() {
12+
if in_code_block && is_rust && code_line_ignored_by_rustdoc(line) {
1613
continue;
1714
}
1815

@@ -23,15 +20,15 @@ pub(crate) fn format_docs(src: &str) -> String {
2320
is_rust = is_rust_fence(header);
2421

2522
if is_rust {
26-
line = Cow::Borrowed("```rust");
23+
line = "```rust";
2724
}
2825
}
2926
}
3027

3128
if in_code_block {
32-
let trimmed = line.trim();
29+
let trimmed = line.trim_start();
3330
if trimmed.starts_with("##") {
34-
line = Cow::Owned(line.replacen("##", "#", 1));
31+
line = &trimmed[1..];
3532
}
3633
}
3734

0 commit comments

Comments
 (0)