Skip to content

Commit 974d75c

Browse files
committed
perf: remainder
1 parent b45b001 commit 974d75c

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

src/replace_source.rs

+11-6
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ impl<T: Source> ReplaceSource<T> {
112112
}
113113

114114
/// Create a replacement with content at `[start, end)`.
115+
#[inline]
115116
pub fn replace(
116117
&mut self,
117118
start: u32,
@@ -663,10 +664,14 @@ impl<T: Source> StreamChunks for ReplaceSource<T> {
663664

664665
// Insert remaining replacements content split into chunks by lines
665666
let mut line = result.generated_line as i64 + generated_line_offset;
666-
let matches: Vec<Rope> = split_into_lines(&remainder).collect();
667-
for (m, content_line) in matches.iter().enumerate() {
667+
let lines: Vec<Rope> = split_into_lines(&remainder).collect();
668+
let lines_len = lines.len();
669+
for (m, content_line) in lines.into_iter().enumerate() {
670+
let newline = content_line.ends_with("\n");
671+
let content_line_len = content_line.len();
672+
668673
on_chunk(
669-
Some(content_line.clone()),
674+
Some(content_line),
670675
Mapping {
671676
generated_line: line as u32,
672677
generated_column: ((result.generated_column as i64)
@@ -679,11 +684,11 @@ impl<T: Source> StreamChunks for ReplaceSource<T> {
679684
},
680685
);
681686

682-
if m == matches.len() - 1 && !content_line.ends_with("\n") {
687+
if m == lines_len - 1 && !newline {
683688
if generated_column_offset_line == line {
684-
generated_column_offset += content_line.len() as i64;
689+
generated_column_offset += content_line_len as i64;
685690
} else {
686-
generated_column_offset = content_line.len() as i64;
691+
generated_column_offset = content_line_len as i64;
687692
generated_column_offset_line = line;
688693
}
689694
} else {

0 commit comments

Comments
 (0)