Skip to content

Commit 30c0657

Browse files
committed
perf: remove WithIndices
1 parent 9cca1a9 commit 30c0657

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

src/replace_source.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ use rustc_hash::FxHashMap as HashMap;
1212

1313
use crate::{
1414
helpers::{get_map, split_into_lines, GeneratedInfo, StreamChunks},
15-
with_indices::WithIndices,
1615
MapOptions, Mapping, OriginalLocation, Source, SourceMap,
1716
};
1817

@@ -312,17 +311,25 @@ impl<'a, T: Source> StreamChunks<'a> for ReplaceSource<T> {
312311
source_content_lines.borrow().get(source_index as usize)
313312
{
314313
if let Some(content_line) = content_lines.get(line as usize - 1) {
315-
WithIndices::new(content_line).substring(
316-
column as usize,
317-
column as usize + expected_chunk.len(),
318-
) == expected_chunk
314+
match content_line
315+
.char_indices()
316+
.nth(column as usize)
317+
.map(|(byte_index, _)| byte_index)
318+
{
319+
Some(byte_index) => {
320+
content_line.get(byte_index..byte_index + expected_chunk.len())
321+
== Some(expected_chunk)
322+
}
323+
None => false,
324+
}
319325
} else {
320326
false
321327
}
322328
} else {
323329
false
324330
}
325331
};
332+
326333
let result = self.inner.stream_chunks(
327334
&MapOptions {
328335
columns: options.columns,

0 commit comments

Comments
 (0)